You are here

Form.html.twig in Drupal 7 to 8/9 Module Upgrader 8

Contains \Drupal\{{ module }}\Form\{{ class }}.

File

templates/Form.html.twig
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains \Drupal\{{ module }}\Form\{{ class }}.
  5. */
  6. namespace Drupal\{{ module }}\Form;
  7. use Drupal\Core\Form\{% if config %}Config{% endif %}FormBase;
  8. use Drupal\Core\Form\FormStateInterface;
  9. use Drupal\Core\Render\Element;
  10. class {{ class }} extends {% if config %}Config{% endif %}FormBase {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function getFormId() {
  15. return '{{ form_id }}';
  16. }
  17. {% if config %}
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function submitForm(array &$form, FormStateInterface $form_state) {
  22. $config = $this->config('{{ module }}.settings');
  23. foreach (Element::children($form) as $variable) {
  24. $config->set($variable, $form_state->getValue($form[$variable]['#parents']));
  25. }
  26. $config->save();
  27. if (method_exists($this, '_submitForm')) {
  28. $this->_submitForm($form, $form_state);
  29. }
  30. parent::submitForm($form, $form_state);
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. protected function getEditableConfigNames() {
  36. return ['{{ module }}.settings'];
  37. }
  38. {% endif %}
  39. }
  40. ?>