function DevelController::stateSystemPage

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

Builds the state variable overview page.

Return value

array Array of page elements to render.

1 string reference to 'DevelController::stateSystemPage'
devel.routing.yml in ./devel.routing.yml
devel.routing.yml

File

src/Controller/DevelController.php, line 134

Class

DevelController
Returns responses for devel module routes.

Namespace

Drupal\devel\Controller

Code

public function stateSystemPage() : array {
    $can_edit = $this->currentUser
        ->hasPermission('administer site configuration');
    $header = [
        'name' => $this->t('Name'),
        'value' => $this->t('Value'),
    ];
    if ($can_edit) {
        $header['edit'] = $this->t('Operations');
    }
    $rows = [];
    // State class doesn't have getAll method so we get all states from the
    // KeyValueStorage.
    foreach ($this->keyValue('state')
        ->getAll() as $state_name => $state) {
        $rows[$state_name] = [
            'name' => [
                'data' => $state_name,
                'class' => 'table-filter-text-source',
            ],
            'value' => [
                'data' => $this->dumper
                    ->export($state),
            ],
        ];
        if ($can_edit) {
            $operations['edit'] = [
                'title' => $this->t('Edit'),
                'url' => Url::fromRoute('devel.system_state_edit', [
                    'state_name' => $state_name,
                ]),
            ];
            $rows[$state_name]['edit'] = [
                'data' => [
                    '#type' => 'operations',
                    '#links' => $operations,
                ],
            ];
        }
    }
    $output['states'] = [
        '#type' => 'devel_table_filter',
        '#filter_label' => $this->t('Search'),
        '#filter_placeholder' => $this->t('Enter state name'),
        '#filter_title' => $this->t('Enter a part of the state name to filter by.'),
        '#header' => $header,
        '#rows' => $rows,
        '#empty' => $this->t('No state variables found.'),
        '#attributes' => [
            'class' => [
                'devel-state-list',
            ],
        ],
    ];
    return $output;
}