92f59270dc35501d84d973cb5d3c6912aa748dc1
[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 elements info overview page.
58    *
59    * @return array
60    *   Array of page elements to render.
61    */
62   public function elementsPage() {
63     $element_info_manager = \Drupal::service('element_info');
64
65     $elements_info = array();
66     foreach ($element_info_manager->getDefinitions() as $element_type => $definition) {
67       $elements_info[$element_type] = $definition + $element_info_manager->getInfo($element_type);
68     }
69
70     ksort($elements_info);
71
72     return $this->dumper->exportAsRenderable($elements_info);
73   }
74
75   /**
76    * Builds the fields info overview page.
77    *
78    * @return array
79    *   Array of page elements to render.
80    */
81   public function fieldInfoPage() {
82     $fields = FieldStorageConfig::loadMultiple();
83     ksort($fields);
84     $output['fields'] = $this->dumper->exportAsRenderable($fields, $this->t('Fields'));
85
86     $field_instances = FieldConfig::loadMultiple();
87     ksort($field_instances);
88     $output['instances'] = $this->dumper->exportAsRenderable($field_instances, $this->t('Instances'));
89
90     $bundles = \Drupal::service('entity_type.bundle.info')->getAllBundleInfo();
91     ksort($bundles);
92     $output['bundles'] = $this->dumper->exportAsRenderable($bundles, $this->t('Bundles'));
93
94     $field_types = \Drupal::service('plugin.manager.field.field_type')->getUiDefinitions();
95     ksort($field_types);
96     $output['field_types'] = $this->dumper->exportAsRenderable($field_types, $this->t('Field types'));
97
98     $formatter_types = \Drupal::service('plugin.manager.field.formatter')->getDefinitions();
99     ksort($formatter_types);
100     $output['formatter_types'] = $this->dumper->exportAsRenderable($formatter_types, $this->t('Formatter types'));
101
102     $widget_types = \Drupal::service('plugin.manager.field.widget')->getDefinitions();
103     ksort($widget_types);
104     $output['widget_types'] = $this->dumper->exportAsRenderable($widget_types, $this->t('Widget types'));
105
106     return $output;
107   }
108
109   /**
110    * Builds the entity types overview page.
111    *
112    * @return array
113    *   Array of page elements to render.
114    */
115   public function entityInfoPage() {
116     $types = $this->entityTypeManager()->getDefinitions();
117     ksort($types);
118     return $this->dumper->exportAsRenderable($types);
119   }
120
121   /**
122    * Builds the state variable overview page.
123    *
124    * @return array
125    *   Array of page elements to render.
126    */
127   public function stateSystemPage() {
128     $output['#attached']['library'][] = 'system/drupal.system.modules';
129
130     $output['filters'] = array(
131       '#type' => 'container',
132       '#attributes' => array(
133         'class' => array('table-filter', 'js-show'),
134       ),
135     );
136
137     $output['filters']['text'] = array(
138       '#type' => 'search',
139       '#title' => $this->t('Search'),
140       '#size' => 30,
141       '#placeholder' => $this->t('Enter state name'),
142       '#attributes' => array(
143         'class' => array('table-filter-text'),
144         'data-table' => '.devel-state-list',
145         'autocomplete' => 'off',
146         'title' => $this->t('Enter a part of the state name to filter by.'),
147       ),
148     );
149
150     $can_edit = $this->currentUser()->hasPermission('administer site configuration');
151
152     $header = array(
153       'name' => $this->t('Name'),
154       'value' => $this->t('Value'),
155     );
156
157     if ($can_edit) {
158       $header['edit'] = $this->t('Operations');
159     }
160
161     $rows = array();
162     // State class doesn't have getAll method so we get all states from the
163     // KeyValueStorage.
164     foreach ($this->keyValue('state')->getAll() as $state_name => $state) {
165       $rows[$state_name] = array(
166         'name' => array(
167           'data' => $state_name,
168           'class' => 'table-filter-text-source',
169         ),
170         'value' => array(
171           'data' => $this->dumper->export($state),
172         ),
173       );
174
175       if ($can_edit) {
176         $operations['edit'] = array(
177           'title' => $this->t('Edit'),
178           'url' => Url::fromRoute('devel.system_state_edit', array('state_name' => $state_name)),
179         );
180         $rows[$state_name]['edit'] = array(
181           'data' => array('#type' => 'operations', '#links' => $operations),
182         );
183       }
184     }
185
186     $output['states'] = array(
187       '#type' => 'table',
188       '#header' => $header,
189       '#rows' => $rows,
190       '#empty' => $this->t('No state variables found.'),
191       '#attributes' => array(
192         'class' => array('devel-state-list'),
193       ),
194     );
195
196     return $output;
197   }
198
199   /**
200    * Builds the session overview page.
201    *
202    * @return array
203    *   Array of page elements to render.
204    */
205   public function session() {
206     $output['description'] = array(
207       '#markup' => '<p>' . $this->t('Here are the contents of your $_SESSION variable.') . '</p>',
208     );
209     $output['session'] = array(
210       '#type' => 'table',
211       '#header' => array($this->t('Session name'), $this->t('Session ID')),
212       '#rows' => array(array(session_name(), session_id())),
213       '#empty' => $this->t('No session available.'),
214     );
215     $output['data'] = $this->dumper->exportAsRenderable($_SESSION);
216
217     return $output;
218   }
219
220 }