3 namespace Drupal\devel\Controller;
5 use Drupal\Core\Controller\ControllerBase;
7 use Drupal\devel\DevelDumperManagerInterface;
8 use Drupal\field\Entity\FieldConfig;
9 use Drupal\field\Entity\FieldStorageConfig;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
13 * Returns responses for devel module routes.
15 class DevelController extends ControllerBase {
20 * @var \Drupal\devel\DevelDumperManagerInterface
25 * EntityDebugController constructor.
27 * @param \Drupal\devel\DevelDumperManagerInterface $dumper
30 public function __construct(DevelDumperManagerInterface $dumper) {
31 $this->dumper = $dumper;
37 public static function create(ContainerInterface $container) {
38 return new static($container->get('devel.dumper'));
42 * Clears all caches, then redirects to the previous page.
44 public function cacheClear() {
45 drupal_flush_all_caches();
46 drupal_set_message('Cache cleared.');
47 return $this->redirect('<front>');
50 public function themeRegistry() {
51 $hooks = theme_get_registry();
53 return $this->dumper->exportAsRenderable($hooks);
57 * Builds the elements info overview page.
60 * Array of page elements to render.
62 public function elementsPage() {
63 $element_info_manager = \Drupal::service('element_info');
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);
70 ksort($elements_info);
72 return $this->dumper->exportAsRenderable($elements_info);
76 * Builds the fields info overview page.
79 * Array of page elements to render.
81 public function fieldInfoPage() {
82 $fields = FieldStorageConfig::loadMultiple();
84 $output['fields'] = $this->dumper->exportAsRenderable($fields, $this->t('Fields'));
86 $field_instances = FieldConfig::loadMultiple();
87 ksort($field_instances);
88 $output['instances'] = $this->dumper->exportAsRenderable($field_instances, $this->t('Instances'));
90 $bundles = \Drupal::service('entity_type.bundle.info')->getAllBundleInfo();
92 $output['bundles'] = $this->dumper->exportAsRenderable($bundles, $this->t('Bundles'));
94 $field_types = \Drupal::service('plugin.manager.field.field_type')->getUiDefinitions();
96 $output['field_types'] = $this->dumper->exportAsRenderable($field_types, $this->t('Field types'));
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'));
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'));
110 * Builds the entity types overview page.
113 * Array of page elements to render.
115 public function entityInfoPage() {
116 $types = $this->entityTypeManager()->getDefinitions();
118 return $this->dumper->exportAsRenderable($types);
122 * Builds the state variable overview page.
125 * Array of page elements to render.
127 public function stateSystemPage() {
128 $output['#attached']['library'][] = 'system/drupal.system.modules';
130 $output['filters'] = array(
131 '#type' => 'container',
132 '#attributes' => array(
133 'class' => array('table-filter', 'js-show'),
137 $output['filters']['text'] = array(
139 '#title' => $this->t('Search'),
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.'),
150 $can_edit = $this->currentUser()->hasPermission('administer site configuration');
153 'name' => $this->t('Name'),
154 'value' => $this->t('Value'),
158 $header['edit'] = $this->t('Operations');
162 // State class doesn't have getAll method so we get all states from the
164 foreach ($this->keyValue('state')->getAll() as $state_name => $state) {
165 $rows[$state_name] = array(
167 'data' => $state_name,
168 'class' => 'table-filter-text-source',
171 'data' => $this->dumper->export($state),
176 $operations['edit'] = array(
177 'title' => $this->t('Edit'),
178 'url' => Url::fromRoute('devel.system_state_edit', array('state_name' => $state_name)),
180 $rows[$state_name]['edit'] = array(
181 'data' => array('#type' => 'operations', '#links' => $operations),
186 $output['states'] = array(
188 '#header' => $header,
190 '#empty' => $this->t('No state variables found.'),
191 '#attributes' => array(
192 'class' => array('devel-state-list'),
200 * Builds the session overview page.
203 * Array of page elements to render.
205 public function session() {
206 $output['description'] = array(
207 '#markup' => '<p>' . $this->t('Here are the contents of your $_SESSION variable.') . '</p>',
209 $output['session'] = array(
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.'),
215 $output['data'] = $this->dumper->exportAsRenderable($_SESSION);