2c3a7b4def1819e2c6747c0d7b39c63b0d91ae66
[yaffs-website] / web / modules / contrib / devel / src / Controller / DevelController.php
1 <?php
2
3 namespace Drupal\devel\Controller;
4
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\Core\Url;
7 use Drupal\devel\DevelDumperManagerInterface;
8 use Drupal\field\Entity\FieldConfig;
9 use Drupal\field\Entity\FieldStorageConfig;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11
12 /**
13  * Returns responses for devel module routes.
14  */
15 class DevelController extends ControllerBase {
16
17   /**
18    * The dumper service.
19    *
20    * @var \Drupal\devel\DevelDumperManagerInterface
21    */
22   protected $dumper;
23
24   /**
25    * EntityDebugController constructor.
26    *
27    * @param \Drupal\devel\DevelDumperManagerInterface $dumper
28    *   The dumper service.
29    */
30   public function __construct(DevelDumperManagerInterface $dumper) {
31     $this->dumper = $dumper;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public static function create(ContainerInterface $container) {
38     return new static($container->get('devel.dumper'));
39   }
40
41   /**
42    * Clears all caches, then redirects to the previous page.
43    */
44   public function cacheClear() {
45     drupal_flush_all_caches();
46     drupal_set_message('Cache cleared.');
47     return $this->redirect('<front>');
48   }
49
50   public function themeRegistry() {
51     $hooks = theme_get_registry();
52     ksort($hooks);
53     return $this->dumper->exportAsRenderable($hooks);
54   }
55
56   /**
57    * Builds the fields info overview page.
58    *
59    * @return array
60    *   Array of page elements to render.
61    */
62   public function fieldInfoPage() {
63     $fields = FieldStorageConfig::loadMultiple();
64     ksort($fields);
65     $output['fields'] = $this->dumper->exportAsRenderable($fields, $this->t('Fields'));
66
67     $field_instances = FieldConfig::loadMultiple();
68     ksort($field_instances);
69     $output['instances'] = $this->dumper->exportAsRenderable($field_instances, $this->t('Instances'));
70
71     $bundles = \Drupal::service('entity_type.bundle.info')->getAllBundleInfo();
72     ksort($bundles);
73     $output['bundles'] = $this->dumper->exportAsRenderable($bundles, $this->t('Bundles'));
74
75     $field_types = \Drupal::service('plugin.manager.field.field_type')->getUiDefinitions();
76     ksort($field_types);
77     $output['field_types'] = $this->dumper->exportAsRenderable($field_types, $this->t('Field types'));
78
79     $formatter_types = \Drupal::service('plugin.manager.field.formatter')->getDefinitions();
80     ksort($formatter_types);
81     $output['formatter_types'] = $this->dumper->exportAsRenderable($formatter_types, $this->t('Formatter types'));
82
83     $widget_types = \Drupal::service('plugin.manager.field.widget')->getDefinitions();
84     ksort($widget_types);
85     $output['widget_types'] = $this->dumper->exportAsRenderable($widget_types, $this->t('Widget types'));
86
87     return $output;
88   }
89
90   /**
91    * Builds the state variable overview page.
92    *
93    * @return array
94    *   Array of page elements to render.
95    */
96   public function stateSystemPage() {
97     $output['#attached']['library'][] = 'system/drupal.system.modules';
98
99     $output['filters'] = array(
100       '#type' => 'container',
101       '#attributes' => array(
102         'class' => array('table-filter', 'js-show'),
103       ),
104     );
105
106     $output['filters']['text'] = array(
107       '#type' => 'search',
108       '#title' => $this->t('Search'),
109       '#size' => 30,
110       '#placeholder' => $this->t('Enter state name'),
111       '#attributes' => array(
112         'class' => array('table-filter-text'),
113         'data-table' => '.devel-state-list',
114         'autocomplete' => 'off',
115         'title' => $this->t('Enter a part of the state name to filter by.'),
116       ),
117     );
118
119     $can_edit = $this->currentUser()->hasPermission('administer site configuration');
120
121     $header = array(
122       'name' => $this->t('Name'),
123       'value' => $this->t('Value'),
124     );
125
126     if ($can_edit) {
127       $header['edit'] = $this->t('Operations');
128     }
129
130     $rows = array();
131     // State class doesn't have getAll method so we get all states from the
132     // KeyValueStorage.
133     foreach ($this->keyValue('state')->getAll() as $state_name => $state) {
134       $rows[$state_name] = array(
135         'name' => array(
136           'data' => $state_name,
137           'class' => 'table-filter-text-source',
138         ),
139         'value' => array(
140           'data' => $this->dumper->export($state),
141         ),
142       );
143
144       if ($can_edit) {
145         $operations['edit'] = array(
146           'title' => $this->t('Edit'),
147           'url' => Url::fromRoute('devel.system_state_edit', array('state_name' => $state_name)),
148         );
149         $rows[$state_name]['edit'] = array(
150           'data' => array('#type' => 'operations', '#links' => $operations),
151         );
152       }
153     }
154
155     $output['states'] = array(
156       '#type' => 'table',
157       '#header' => $header,
158       '#rows' => $rows,
159       '#empty' => $this->t('No state variables found.'),
160       '#attributes' => array(
161         'class' => array('devel-state-list'),
162       ),
163     );
164
165     return $output;
166   }
167
168   /**
169    * Builds the session overview page.
170    *
171    * @return array
172    *   Array of page elements to render.
173    */
174   public function session() {
175     $output['description'] = array(
176       '#markup' => '<p>' . $this->t('Here are the contents of your $_SESSION variable.') . '</p>',
177     );
178     $output['session'] = array(
179       '#type' => 'table',
180       '#header' => array($this->t('Session name'), $this->t('Session ID')),
181       '#rows' => array(array(session_name(), session_id())),
182       '#empty' => $this->t('No session available.'),
183     );
184     $output['data'] = $this->dumper->exportAsRenderable($_SESSION);
185
186     return $output;
187   }
188
189 }