function ContainerInfoController::serviceList

Same name in other branches
  1. 8.x-1.x src/Controller/ContainerInfoController.php \Drupal\devel\Controller\ContainerInfoController::serviceList()
  2. 5.x src/Controller/ContainerInfoController.php \Drupal\devel\Controller\ContainerInfoController::serviceList()

Builds the services overview page.

Return value

array A render array as expected by the renderer.

1 string reference to 'ContainerInfoController::serviceList'
devel.routing.yml in ./devel.routing.yml
devel.routing.yml

File

src/Controller/ContainerInfoController.php, line 66

Class

ContainerInfoController
Provides route responses for the container info pages.

Namespace

Drupal\devel\Controller

Code

public function serviceList() {
    $headers = [
        $this->t('ID'),
        $this->t('Class'),
        $this->t('Alias'),
        $this->t('Operations'),
    ];
    $rows = [];
    if ($container = $this->kernel
        ->getCachedContainerDefinition()) {
        foreach ($container['services'] as $service_id => $definition) {
            $service = unserialize($definition);
            $row['id'] = [
                'data' => $service_id,
                'filter' => TRUE,
            ];
            $row['class'] = [
                'data' => $service['class'] ?? '',
                'filter' => TRUE,
            ];
            $row['alias'] = [
                'data' => array_search($service_id, $container['aliases']) ?: '',
                'filter' => TRUE,
            ];
            $row['operations']['data'] = [
                '#type' => 'operations',
                '#links' => [
                    'devel' => [
                        'title' => $this->t('Devel'),
                        'url' => Url::fromRoute('devel.container_info.service.detail', [
                            'service_id' => $service_id,
                        ]),
                        'attributes' => [
                            'class' => [
                                'use-ajax',
                            ],
                            'data-dialog-type' => 'modal',
                            'data-dialog-options' => Json::encode([
                                'width' => 700,
                                'minHeight' => 500,
                            ]),
                        ],
                    ],
                ],
            ];
            $rows[$service_id] = $row;
        }
        ksort($rows);
    }
    $output['services'] = [
        '#type' => 'devel_table_filter',
        '#filter_label' => $this->t('Search'),
        '#filter_placeholder' => $this->t('Enter service id, alias or class'),
        '#filter_description' => $this->t('Enter a part of the service id, service alias or class to filter by.'),
        '#header' => $headers,
        '#rows' => $rows,
        '#empty' => $this->t('No services found.'),
        '#sticky' => TRUE,
        '#attributes' => [
            'class' => [
                'devel-service-list',
            ],
        ],
    ];
    return $output;
}