You are here

public function LoggerFilterForm::buildForm in MongoDB 8

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

src/Form/LoggerFilterForm.php, line 47
Contains \Drupal\mongodb\Form\DblogFilterForm.

Class

LoggerFilterForm
Provides the MongoDB logging filter form.

Namespace

Drupal\mongodb\Form

Code

public function buildForm(array $form, array &$form_state) {
  $filters = $this
    ->getFilters();
  $form['filters'] = array(
    '#type' => 'details',
    '#title' => t('Filter log messages'),
    '#open' => !empty($_SESSION['mongodb_watchdog_overview_filter']),
    '#weight' => 1,
  );
  foreach ($filters as $key => $filter) {
    $form['filters']['status'][$key] = array(
      '#title' => $filter['title'],
      '#type' => 'select',
      '#multiple' => TRUE,
      '#size' => 8,
      '#options' => $filter['options'],
    );
    if (!empty($_SESSION['mongodb_watchdog_overview_filter'][$key])) {
      $form['filters']['status'][$key]['#default_value'] = $_SESSION['mongodb_watchdog_overview_filter'][$key];
    }
  }
  $form['filters']['actions'] = array(
    '#type' => 'actions',
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
  );
  $form['filters']['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Filter'),
  );
  if (!empty($_SESSION['mongodb_watchdog_overview_filter'])) {
    $form['filters']['actions']['reset'] = array(
      '#type' => 'submit',
      '#value' => $this
        ->t('Reset'),
      '#limit_validation_errors' => array(),
      '#submit' => array(
        array(
          $this,
          'resetForm',
        ),
      ),
    );
  }
  $form['#weight'] = -2;
  return $form;
}