Same name and namespace in other branches
  1. 8.9.x core/modules/dblog/src/Form/DblogFilterForm.php \Drupal\dblog\Form\DblogFilterForm::buildForm()
  2. 9 core/modules/dblog/src/Form/DblogFilterForm.php \Drupal\dblog\Form\DblogFilterForm::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/dblog/src/Form/DblogFilterForm.php, line 25

Class

DblogFilterForm
Provides the database logging filter form.

Namespace

Drupal\dblog\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $filters = dblog_filters();
  $form['filters'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Filter log messages'),
    '#open' => TRUE,
  ];
  $session_filters = $this
    ->getRequest()
    ->getSession()
    ->get('dblog_overview_filter', []);
  foreach ($filters as $key => $filter) {
    $form['filters']['status'][$key] = [
      '#title' => $filter['title'],
      '#type' => 'select',
      '#multiple' => TRUE,
      '#size' => 8,
      '#options' => $filter['options'],
    ];
    if (!empty($session_filters[$key])) {
      $form['filters']['status'][$key]['#default_value'] = $session_filters[$key];
    }
  }
  $form['filters']['actions'] = [
    '#type' => 'actions',
    '#attributes' => [
      'class' => [
        'container-inline',
      ],
    ],
  ];
  $form['filters']['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Filter'),
  ];
  if (!empty($session_filters)) {
    $form['filters']['actions']['reset'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Reset'),
      '#limit_validation_errors' => [],
      '#submit' => [
        '::resetForm',
      ],
    ];
  }
  return $form;
}