function DevelopmentSettingsForm::buildForm

Same name and namespace in other branches
  1. 11.x core/modules/system/src/Form/DevelopmentSettingsForm.php \Drupal\system\Form\DevelopmentSettingsForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

core/modules/system/src/Form/DevelopmentSettingsForm.php, line 54

Class

DevelopmentSettingsForm
Configure development settings for this site.

Namespace

Drupal\system\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $development_settings = $this->keyValueFactory
    ->get('development_settings');
  $form['description'] = [
    '#plain_text' => $this->t('These settings should only be enabled on development environments and never on production.'),
  ];
  $twig_debug = $development_settings->get('twig_debug', FALSE);
  $twig_cache_disable = $development_settings->get('twig_cache_disable', FALSE);
  $twig_development_state_conditions = [
    'input[data-drupal-selector="edit-twig-development-mode"]' => [
      'checked' => TRUE,
    ],
  ];
  $form['disable_rendered_output_cache_bins'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('Do not cache markup'),
    '#description' => $this->t('Disables render cache, dynamic page cache, and page cache.'),
    '#default_value' => $development_settings->get('disable_rendered_output_cache_bins', FALSE),
  ];
  $form['twig_development_mode'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('Twig development mode'),
    '#description' => $this->t('Exposes Twig development settings.'),
    '#default_value' => $twig_debug || $twig_cache_disable,
  ];
  $form['twig_development'] = [
    '#type' => 'fieldset',
    '#title' => $this->t('Twig development mode'),
    '#states' => [
      'visible' => $twig_development_state_conditions,
    ],
  ];
  $form['twig_development']['twig_debug'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('Twig debug mode'),
    '#description' => $this->t("Provides Twig's <code>dump()</code> function for debugging, outputs template suggestions to HTML comments, and automatically recompile Twig templates after changes."),
    '#default_value' => $twig_debug,
  ];
  $form['twig_development']['twig_cache_disable'] = [
    '#type' => 'checkbox',
    '#title' => $this->t('Disable Twig cache'),
    '#description' => $this->t('Twig templates are not cached and are always compiled when rendered.'),
    '#default_value' => $twig_cache_disable,
  ];
  if (!$twig_debug && !$twig_cache_disable) {
    $form['twig_development']['twig_debug']['#states'] = [
      'checked' => $twig_development_state_conditions,
    ];
    $form['twig_development']['twig_cache_disable']['#states'] = [
      'checked' => $twig_development_state_conditions,
    ];
  }
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this->t('Save settings'),
    '#button_type' => 'primary',
  ];
  return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.