"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/dblog/src/Form/DblogFilterForm.php" (26 Nov 2020, 2559 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "DblogFilterForm.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\dblog\Form;
    4 
    5 use Drupal\Core\Form\FormBase;
    6 use Drupal\Core\Form\FormStateInterface;
    7 
    8 /**
    9  * Provides the database logging filter form.
   10  *
   11  * @internal
   12  */
   13 class DblogFilterForm extends FormBase {
   14 
   15   /**
   16    * {@inheritdoc}
   17    */
   18   public function getFormId() {
   19     return 'dblog_filter_form';
   20   }
   21 
   22   /**
   23    * {@inheritdoc}
   24    */
   25   public function buildForm(array $form, FormStateInterface $form_state) {
   26     $filters = dblog_filters();
   27 
   28     $form['filters'] = [
   29       '#type' => 'details',
   30       '#title' => $this->t('Filter log messages'),
   31       '#open' => TRUE,
   32     ];
   33     foreach ($filters as $key => $filter) {
   34       $form['filters']['status'][$key] = [
   35         '#title' => $filter['title'],
   36         '#type' => 'select',
   37         '#multiple' => TRUE,
   38         '#size' => 8,
   39         '#options' => $filter['options'],
   40       ];
   41       if (!empty($_SESSION['dblog_overview_filter'][$key])) {
   42         $form['filters']['status'][$key]['#default_value'] = $_SESSION['dblog_overview_filter'][$key];
   43       }
   44     }
   45 
   46     $form['filters']['actions'] = [
   47       '#type' => 'actions',
   48       '#attributes' => ['class' => ['container-inline']],
   49     ];
   50     $form['filters']['actions']['submit'] = [
   51       '#type' => 'submit',
   52       '#value' => $this->t('Filter'),
   53     ];
   54     if (!empty($_SESSION['dblog_overview_filter'])) {
   55       $form['filters']['actions']['reset'] = [
   56         '#type' => 'submit',
   57         '#value' => $this->t('Reset'),
   58         '#limit_validation_errors' => [],
   59         '#submit' => ['::resetForm'],
   60       ];
   61     }
   62     return $form;
   63   }
   64 
   65   /**
   66    * {@inheritdoc}
   67    */
   68   public function validateForm(array &$form, FormStateInterface $form_state) {
   69     if ($form_state->isValueEmpty('type') && $form_state->isValueEmpty('severity')) {
   70       $form_state->setErrorByName('type', $this->t('You must select something to filter by.'));
   71     }
   72   }
   73 
   74   /**
   75    * {@inheritdoc}
   76    */
   77   public function submitForm(array &$form, FormStateInterface $form_state) {
   78     $filters = dblog_filters();
   79     foreach ($filters as $name => $filter) {
   80       if ($form_state->hasValue($name)) {
   81         $_SESSION['dblog_overview_filter'][$name] = $form_state->getValue($name);
   82       }
   83     }
   84   }
   85 
   86   /**
   87    * Resets the filter form.
   88    *
   89    * @param array $form
   90    *   An associative array containing the structure of the form.
   91    * @param \Drupal\Core\Form\FormStateInterface $form_state
   92    *   The current state of the form.
   93    */
   94   public function resetForm(array &$form, FormStateInterface $form_state) {
   95     $_SESSION['dblog_overview_filter'] = [];
   96   }
   97 
   98 }