function ElementInfoController::elementList

Same name in other branches
  1. 4.x src/Controller/ElementInfoController.php \Drupal\devel\Controller\ElementInfoController::elementList()

Builds the element overview page.

Return value

array A render array as expected by the renderer.

1 string reference to 'ElementInfoController::elementList'
devel.routing.yml in ./devel.routing.yml
devel.routing.yml

File

src/Controller/ElementInfoController.php, line 46

Class

ElementInfoController
Provides route responses for the element info page.

Namespace

Drupal\devel\Controller

Code

public function elementList() : array {
    $headers = [
        $this->t('Name'),
        $this->t('Provider'),
        $this->t('Class'),
        $this->t('Operations'),
    ];
    $rows = [];
    foreach ($this->elementInfo
        ->getDefinitions() as $element_type => $definition) {
        $row['name'] = [
            'data' => $element_type,
            'filter' => TRUE,
        ];
        $row['provider'] = [
            'data' => $definition['provider'],
            'filter' => TRUE,
        ];
        $row['class'] = [
            'data' => $definition['class'],
            'filter' => TRUE,
        ];
        $row['operations']['data'] = [
            '#type' => 'operations',
            '#links' => [
                'devel' => [
                    'title' => $this->t('Devel'),
                    'url' => Url::fromRoute('devel.elements_page.detail', [
                        'element_name' => $element_type,
                    ]),
                    'attributes' => [
                        'class' => [
                            'use-ajax',
                        ],
                        'data-dialog-type' => 'modal',
                        'data-dialog-options' => Json::encode([
                            'width' => 700,
                            'minHeight' => 500,
                        ]),
                    ],
                ],
            ],
        ];
        $rows[$element_type] = $row;
    }
    ksort($rows);
    $output['elements'] = [
        '#type' => 'devel_table_filter',
        '#filter_label' => $this->t('Search'),
        '#filter_placeholder' => $this->t('Enter element id, provider or class'),
        '#filter_description' => $this->t('Enter a part of the element id, provider or class to filter by.'),
        '#header' => $headers,
        '#rows' => $rows,
        '#empty' => $this->t('No elements found.'),
        '#sticky' => TRUE,
        '#attributes' => [
            'class' => [
                'devel-element-list',
            ],
        ],
    ];
    return $output;
}