f0993e77baaadcb9e16927a28e612eedfc9ea018
[yaffs-website] / web / modules / contrib / devel / src / Form / ConfigsList.php
1 <?php
2
3 namespace Drupal\devel\Form;
4
5 use Drupal\Component\Utility\Html;
6 use Drupal\Core\Form\FormBase;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\Core\Url;
9
10 /**
11  * Form that displays all the config variables to edit them.
12  */
13 class ConfigsList extends FormBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getFormId() {
19     return 'devel_config_system_form';
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   public function buildForm(array $form, FormStateInterface $form_state, $filter = '') {
26     $form['filter'] = array(
27       '#type' => 'details',
28       '#title' => t('Filter variables'),
29       '#attributes' => array('class' => array('container-inline')),
30       '#open' => isset($filter) && trim($filter) != '',
31     );
32     $form['filter']['name'] = array(
33       '#type' => 'textfield',
34       '#title' => $this->t('Variable name'),
35       '#title_display' => 'invisible',
36       '#default_value' => $filter,
37     );
38     $form['filter']['show'] = array(
39       '#type' => 'submit',
40       '#value' => $this->t('Filter'),
41     );
42
43     $header = array(
44       'name' => array('data' => $this->t('Name')),
45       'edit' => array('data' => $this->t('Operations')),
46     );
47
48     $rows = array();
49
50     $destination = $this->getDestinationArray();
51
52     // List all the variables filtered if any filter was provided.
53     $names = $this->configFactory()->listAll($filter);
54
55     foreach ($names as $config_name) {
56       $operations['edit'] = array(
57         'title' => $this->t('Edit'),
58         'url' => Url::fromRoute('devel.config_edit', array('config_name' => $config_name)),
59         'query' => $destination
60       );
61       $rows[] = array(
62         'name' => $config_name,
63         'operation' => array('data' => array('#type' => 'operations', '#links' => $operations)),
64       );
65     }
66
67     $form['variables'] = array(
68       '#type' => 'table',
69       '#header' => $header,
70       '#rows' => $rows,
71       '#empty' => $this->t('No variables found')
72     );
73
74     return $form;
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   public function submitForm(array &$form, FormStateInterface $form_state) {
81     $filter = $form_state->getValue('name');
82     $form_state->setRedirectUrl(Url::FromRoute('devel.configs_list', array('filter' => Html::escape($filter))));
83   }
84
85 }