function contextual_toolbar in Drupal 9
Same name and namespace in other branches
- 8 core/modules/contextual/contextual.module \contextual_toolbar()
- 10 core/modules/contextual/contextual.module \contextual_toolbar()
Implements hook_toolbar().
File
- core/
modules/ contextual/ contextual.module, line 17 - Adds contextual links to perform actions related to elements on a page.
Code
function contextual_toolbar() {
$items = [];
$items['contextual'] = [
'#cache' => [
'contexts' => [
'user.permissions',
],
],
];
if (!\Drupal::currentUser()
->hasPermission('access contextual links')) {
return $items;
}
$items['contextual'] += [
'#type' => 'toolbar_item',
'tab' => [
'#type' => 'html_tag',
'#tag' => 'button',
'#value' => t('Edit'),
'#attributes' => [
'class' => [
'toolbar-icon',
'toolbar-icon-edit',
],
'aria-pressed' => 'false',
'type' => 'button',
],
],
'#wrapper_attributes' => [
'class' => [
'hidden',
'contextual-toolbar-tab',
],
],
'#attached' => [
'library' => [
'contextual/drupal.contextual-toolbar',
],
],
];
return $items;
}