You are here

public function ElementInfoController::elementList in Devel 8

Same name and namespace in other branches
  1. 8.3 src/Controller/ElementInfoController.php \Drupal\devel\Controller\ElementInfoController::elementList()
  2. 8.2 src/Controller/ElementInfoController.php \Drupal\devel\Controller\ElementInfoController::elementList()
  3. 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 61

Class

ElementInfoController
Provides route responses for the element info page.

Namespace

Drupal\devel\Controller

Code

public function elementList() {
  $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,
      'class' => 'table-filter-text-source',
    ];
    $row['provider'] = [
      'data' => $definition['provider'],
      'class' => 'table-filter-text-source',
    ];
    $row['class'] = [
      'data' => $definition['class'],
      'class' => 'table-filter-text-source',
    ];
    $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['#attached']['library'][] = 'system/drupal.system.modules';
  $output['filters'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'table-filter',
        'js-show',
      ],
    ],
  ];
  $output['filters']['text'] = [
    '#type' => 'search',
    '#title' => $this
      ->t('Search'),
    '#size' => 30,
    '#placeholder' => $this
      ->t('Enter element id, provider or class'),
    '#attributes' => [
      'class' => [
        'table-filter-text',
      ],
      'data-table' => '.devel-filter-text',
      'autocomplete' => 'off',
      'title' => $this
        ->t('Enter a part of the element id, provider or class to filter by.'),
    ],
  ];
  $output['elements'] = [
    '#type' => 'table',
    '#header' => $headers,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No elements found.'),
    '#sticky' => TRUE,
    '#attributes' => [
      'class' => [
        'devel-element-list',
        'devel-filter-text',
      ],
    ],
  ];
  return $output;
}