Version 1
[yaffs-website] / web / modules / contrib / devel / webprofiler / src / Form / ProfilesFilterForm.php
1 <?php
2
3 namespace Drupal\webprofiler\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Url;
8
9 /**
10  * Class ProfilesFilterForm
11  */
12 class ProfilesFilterForm extends FormBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getFormId() {
18     return 'webprofiler_profiles_filter';
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   public function buildForm(array $form, FormStateInterface $form_state) {
25     $form['ip'] = [
26       '#type' => 'textfield',
27       '#title' => $this->t('IP'),
28       '#size' => 30,
29       '#default_value' => $this->getRequest()->query->get('ip'),
30       '#prefix' => '<div class="form--inline clearfix">',
31     ];
32
33     $form['url'] = [
34       '#type' => 'textfield',
35       '#title' => $this->t('Url'),
36       '#size' => 30,
37       '#default_value' => $this->getRequest()->query->get('url'),
38     ];
39
40     $form['method'] = [
41       '#type' => 'select',
42       '#title' => $this->t('Method'),
43       '#options' => ['GET' => 'GET', 'POST' => 'POST'],
44       '#default_value' => $this->getRequest()->query->get('method'),
45     ];
46
47     $limits = [10, 50, 100];
48     $form['limit'] = [
49       '#type' => 'select',
50       '#title' => $this->t('Limit'),
51       '#options' => array_combine($limits, $limits),
52       '#default_value' => $this->getRequest()->query->get('limit'),
53     ];
54
55     $form['actions'] = ['#type' => 'actions'];
56     $form['actions']['filter'] = [
57       '#type' => 'submit',
58       '#value' => t('Filter'),
59       '#attributes' => ['class' => ['button--primary']],
60       '#suffix' => '</div>',
61     ];
62
63     return $form;
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public function submitForm(array &$form, FormStateInterface $form_state) {
70     $ip = $form_state->getValue('ip');// ['values']['ip'];
71     $url = $form_state->getValue('url');
72     $method = $form_state->getValue('method');
73     $limit = $form_state->getValue('limit');
74
75     $url = new Url('webprofiler.admin_list', [], [
76       'query' => [
77         'ip' => $ip,
78         'url' => $url,
79         'method' => $method,
80         'limit' => $limit,
81       ]
82     ]);
83
84     $form_state->setRedirectUrl($url);
85   }
86 }