3 namespace Drupal\devel\Controller;
5 use Drupal\Component\Serialization\Json;
6 use Drupal\Core\Controller\ControllerBase;
7 use Drupal\Core\Render\ElementInfoManagerInterface;
9 use Drupal\devel\DevelDumperManagerInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
14 * Provides route responses for the element info page.
16 class ElementInfoController extends ControllerBase {
19 * Element info manager service.
21 * @var \Drupal\Core\Render\ElementInfoManagerInterface
23 protected $elementInfo;
28 * @var \Drupal\devel\DevelDumperManagerInterface
33 * EventInfoController constructor.
35 * @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info
36 * Element info manager service.
37 * @param \Drupal\devel\DevelDumperManagerInterface $dumper
40 public function __construct(ElementInfoManagerInterface $element_info, DevelDumperManagerInterface $dumper) {
41 $this->elementInfo = $element_info;
42 $this->dumper = $dumper;
48 public static function create(ContainerInterface $container) {
50 $container->get('element_info'),
51 $container->get('devel.dumper')
56 * Builds the element overview page.
59 * A render array as expected by the renderer.
61 public function elementList() {
66 $this->t('Operations'),
71 foreach ($this->elementInfo->getDefinitions() as $element_type => $definition) {
73 'data' => $element_type,
74 'class' => 'table-filter-text-source',
77 'data' => $definition['provider'],
78 'class' => 'table-filter-text-source',
81 'data' => $definition['class'],
82 'class' => 'table-filter-text-source',
84 $row['operations']['data'] = [
85 '#type' => 'operations',
88 'title' => $this->t('Devel'),
89 'url' => Url::fromRoute('devel.elements_page.detail', ['element_name' => $element_type]),
91 'class' => ['use-ajax'],
92 'data-dialog-type' => 'modal',
93 'data-dialog-options' => Json::encode([
102 $rows[$element_type] = $row;
107 $output['#attached']['library'][] = 'system/drupal.system.modules';
109 $output['filters'] = [
110 '#type' => 'container',
112 'class' => ['table-filter', 'js-show'],
115 $output['filters']['text'] = [
117 '#title' => $this->t('Search'),
119 '#placeholder' => $this->t('Enter element id, provider or class'),
121 'class' => ['table-filter-text'],
122 'data-table' => '.devel-filter-text',
123 'autocomplete' => 'off',
124 'title' => $this->t('Enter a part of the element id, provider or class to filter by.'),
127 $output['elements'] = [
129 '#header' => $headers,
131 '#empty' => $this->t('No elements found.'),
134 'class' => ['devel-element-list', 'devel-filter-text'],
142 * Returns a render array representation of the element.
144 * @param string $element_name
145 * The name of the element to retrieve.
148 * A render array containing the element.
150 * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
151 * If the requested element is not defined.
153 public function elementDetail($element_name) {
154 if (!$element = $this->elementInfo->getDefinition($element_name, FALSE)) {
155 throw new NotFoundHttpException();
158 $element += $this->elementInfo->getInfo($element_name);
159 return $this->dumper->exportAsRenderable($element, $element_name);