ConfigFormBase.php 1.38 KB
Newer Older
1 2
<?php

3
namespace Drupal\Core\Form;
4

5
use Drupal\Core\Config\ConfigFactoryInterface;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7 8 9 10

/**
 * Base class for implementing system configuration forms.
 */
11
abstract class ConfigFormBase extends FormBase {
12
  use ConfigFormBaseTrait;
13 14

  /**
15
   * Constructs a \Drupal\system\ConfigFormBase object.
16
   *
17
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
18 19
   *   The factory for configuration objects.
   */
20
  public function __construct(ConfigFactoryInterface $config_factory) {
21
    $this->setConfigFactory($config_factory);
22 23 24
  }

  /**
25
   * {@inheritdoc}
26 27 28
   */
  public static function create(ContainerInterface $container) {
    return new static(
29
      $container->get('config.factory')
30 31
    );
  }
32 33

  /**
34
   * {@inheritdoc}
35
   */
36
  public function buildForm(array $form, FormStateInterface $form_state) {
37
    $form['actions']['#type'] = 'actions';
38
    $form['actions']['submit'] = [
39
      '#type' => 'submit',
40
      '#value' => $this->t('Save configuration'),
41
      '#button_type' => 'primary',
42
    ];
43

44
    // By default, render the form using system-config-form.html.twig.
45
    $form['#theme'] = 'system_config_form';
46 47 48 49 50

    return $form;
  }

  /**
51
   * {@inheritdoc}
52
   */
53
  public function submitForm(array &$form, FormStateInterface $form_state) {
54
    drupal_set_message($this->t('The configuration options have been saved.'));
55 56 57
  }

}