function ToolbarHooks::pageTop

Same name and namespace in other branches
  1. 11.x core/modules/toolbar/src/Hook/ToolbarHooks.php \Drupal\toolbar\Hook\ToolbarHooks::pageTop()

Implements hook_page_top().

Add admin toolbar to the top of the page automatically.

Attributes

#[Hook('page_top')]

File

core/modules/toolbar/src/Hook/ToolbarHooks.php, line 44

Class

ToolbarHooks
Hook implementations for toolbar.

Namespace

Drupal\toolbar\Hook

Code

public function pageTop(array &$page_top) : void {
  $page_top['toolbar'] = [
    '#type' => 'toolbar',
    '#access' => \Drupal::currentUser()->hasPermission('access toolbar'),
    '#cache' => [
      'keys' => [
        'toolbar',
      ],
      'contexts' => [
        'user.permissions',
      ],
    ],
  ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.