1. 8.5.x core/lib/Drupal/Core/Form/ConfigFormBase.php
  2. 8.0.x core/lib/Drupal/Core/Form/ConfigFormBase.php
  3. 8.1.x core/lib/Drupal/Core/Form/ConfigFormBase.php
  4. 8.2.x core/lib/Drupal/Core/Form/ConfigFormBase.php
  5. 8.3.x core/lib/Drupal/Core/Form/ConfigFormBase.php
  6. 8.4.x core/lib/Drupal/Core/Form/ConfigFormBase.php
  7. 8.6.x core/lib/Drupal/Core/Form/ConfigFormBase.php

Namespace

Drupal\Core\Form

File

core/lib/Drupal/Core/Form/ConfigFormBase.php
View source
<?php

namespace Drupal\Core\Form;

use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

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

  /**
   * Constructs a \Drupal\system\ConfigFormBase object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The factory for configuration objects.
   */
  public function __construct(ConfigFactoryInterface $config_factory) {
    $this
      ->setConfigFactory($config_factory);
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'));
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => $this
        ->t('Save configuration'),
      '#button_type' => 'primary',
    );

    // By default, render the form using system-config-form.html.twig.
    $form['#theme'] = 'system_config_form';
    return $form;
  }

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

}

Classes

Namesort descending Description
ConfigFormBase Base class for implementing system configuration forms.