f7829061ecb3b87de66f4a784cdb9dfe094e846d
[yaffs-website] / web / core / modules / path / src / Form / PathFilterForm.php
1 <?php
2
3 namespace Drupal\path\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Provides the path admin overview filter form.
10  */
11 class PathFilterForm extends FormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function getFormId() {
17     return 'path_admin_filter_form';
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   public function buildForm(array $form, FormStateInterface $form_state, $keys = NULL) {
24     $form['#attributes'] = ['class' => ['search-form']];
25     $form['basic'] = [
26       '#type' => 'details',
27       '#title' => $this->t('Filter aliases'),
28       '#open' => TRUE,
29       '#attributes' => ['class' => ['container-inline']],
30     ];
31     $form['basic']['filter'] = [
32       '#type' => 'search',
33       '#title' => 'Path alias',
34       '#title_display' => 'invisible',
35       '#default_value' => $keys,
36       '#maxlength' => 128,
37       '#size' => 25,
38     ];
39     $form['basic']['submit'] = [
40       '#type' => 'submit',
41       '#value' => $this->t('Filter'),
42     ];
43     if ($keys) {
44       $form['basic']['reset'] = [
45         '#type' => 'submit',
46         '#value' => $this->t('Reset'),
47         '#submit' => ['::resetForm'],
48       ];
49     }
50     return $form;
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function submitForm(array &$form, FormStateInterface $form_state) {
57     $form_state->setRedirect('path.admin_overview_filter', [], [
58       'query' => ['search' => trim($form_state->getValue('filter'))],
59     ]);
60   }
61
62   /**
63    * Resets the filter selections.
64    */
65   public function resetForm(array &$form, FormStateInterface $form_state) {
66     $form_state->setRedirect('path.admin_overview');
67   }
68
69 }