52b0ffbb9446a0cf5e3121b2a5799abc909163fa
[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  * @internal
12  */
13 class PathFilterForm extends FormBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getFormId() {
19     return 'path_admin_filter_form';
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   public function buildForm(array $form, FormStateInterface $form_state, $keys = NULL) {
26     $form['#attributes'] = ['class' => ['search-form']];
27     $form['basic'] = [
28       '#type' => 'details',
29       '#title' => $this->t('Filter aliases'),
30       '#open' => TRUE,
31       '#attributes' => ['class' => ['container-inline']],
32     ];
33     $form['basic']['filter'] = [
34       '#type' => 'search',
35       '#title' => $this->t('Path alias'),
36       '#title_display' => 'invisible',
37       '#default_value' => $keys,
38       '#maxlength' => 128,
39       '#size' => 25,
40     ];
41     $form['basic']['submit'] = [
42       '#type' => 'submit',
43       '#value' => $this->t('Filter'),
44     ];
45     if ($keys) {
46       $form['basic']['reset'] = [
47         '#type' => 'submit',
48         '#value' => $this->t('Reset'),
49         '#submit' => ['::resetForm'],
50       ];
51     }
52     return $form;
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   public function submitForm(array &$form, FormStateInterface $form_state) {
59     $form_state->setRedirect('path.admin_overview_filter', [], [
60       'query' => ['search' => trim($form_state->getValue('filter'))],
61     ]);
62   }
63
64   /**
65    * Resets the filter selections.
66    */
67   public function resetForm(array &$form, FormStateInterface $form_state) {
68     $form_state->setRedirect('path.admin_overview');
69   }
70
71 }