{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module_name}}\Form\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module_name}}\Form;
{% endblock %}
{% block use_class %}
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
{% if services is not empty %}
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endif %}
{% endblock %}
{% block use_class_services %}
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class_name }}.
*/
class {{ class_name }} extends ConfigFormBase {% endblock %}
{% block class_create %}
{% if services is not empty %}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
{{ serviceClassInjectionNoOverride(services) }}
return $instance;
}
{% endif %}
{% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'{{module_name}}.{{class_name_short}}',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return '{{form_id}}';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('{{module_name}}.{{class_name_short}}');
{% for input in inputs %}
{% if input.fieldset is defined and input.fieldset is not empty %}
$form['{{ input.fieldset }}']['{{ input.name }}'] = [
{% else %}
$form['{{ input.name }}'] = [
{% endif %}
'#type' => '{{ input.type }}',
'#title' => $this->t('{{ input.label|e }}'),
{% if input.description is defined and input.description|length %}
'#description' => $this->t('{{ input.description|e }}'),
{% endif %}
{% if input.options is defined and input.options is not empty %}
'#options' => {{ input.options }},
{% endif %}
{% if input.maxlength is defined and input.maxlength is not empty %}
'#maxlength' => {{ input.maxlength }},
{% endif %}
{% if input.size is defined and input.size is not empty %}
'#size' => {{ input.size }},
{% endif %}
{% if input.type != 'password_confirm' and input.type != 'fieldset' %}
'#default_value' => $config->get('{{ input.name }}'),
{% endif %}
];
{% endfor %}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this->config('{{module_name}}.{{class_name_short}}')
{% for input in inputs %}
->set('{{ input.name }}', $form_state->getValue('{{ input.name }}'){% if input.type == 'text_format' %}['value']{% endif %})
{% endfor %}
->save();
}
{% endblock %}