You are here

public function DevelController::stateSystemPage in Devel 8

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

Class

DevelController
Returns responses for devel module routes.

Namespace

Drupal\devel\Controller

Code

public function stateSystemPage() {
  $output['#attached']['library'][] = 'system/drupal.system.modules';
  $output['filters'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array(
        'table-filter',
        'js-show',
      ),
    ),
  );
  $output['filters']['text'] = array(
    '#type' => 'search',
    '#title' => $this
      ->t('Search'),
    '#size' => 30,
    '#placeholder' => $this
      ->t('Enter state name'),
    '#attributes' => array(
      'class' => array(
        'table-filter-text',
      ),
      'data-table' => '.devel-state-list',
      'autocomplete' => 'off',
      'title' => $this
        ->t('Enter a part of the state name to filter by.'),
    ),
  );
  $can_edit = $this
    ->currentUser()
    ->hasPermission('administer site configuration');
  $header = array(
    'name' => $this
      ->t('Name'),
    'value' => $this
      ->t('Value'),
  );
  if ($can_edit) {
    $header['edit'] = $this
      ->t('Operations');
  }
  $rows = array();

  // 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] = array(
      'name' => array(
        'data' => $state_name,
        'class' => 'table-filter-text-source',
      ),
      'value' => array(
        'data' => $this->dumper
          ->export($state),
      ),
    );
    if ($can_edit) {
      $operations['edit'] = array(
        'title' => $this
          ->t('Edit'),
        'url' => Url::fromRoute('devel.system_state_edit', array(
          'state_name' => $state_name,
        )),
      );
      $rows[$state_name]['edit'] = array(
        'data' => array(
          '#type' => 'operations',
          '#links' => $operations,
        ),
      );
    }
  }
  $output['states'] = array(
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No state variables found.'),
    '#attributes' => array(
      'class' => array(
        'devel-state-list',
      ),
    ),
  );
  return $output;
}