function ToolbarHooks::pageTop
Same name and namespace in other branches
- 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 60
Class
- ToolbarHooks
- Hook implementations for toolbar.
Namespace
Drupal\toolbar\HookCode
public function pageTop(array &$page_top) : void {
// If navigation is enabled and the user has access to it, don't add the
// toolbar.
if ($this->currentUser
->hasPermission('access navigation') && $this->moduleHandler
->moduleExists('navigation')) {
return;
}
$page_top['toolbar'] = [
'#type' => 'toolbar',
'#access' => $this->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.