function AnnouncementsFeedToolbarHooks::toolbar
Implements hook_toolbar().
Attributes
#[Hook('toolbar')]
File
-
core/
modules/ announcements_feed/ src/ Hook/ AnnouncementsFeedToolbarHooks.php, line 23
Class
- AnnouncementsFeedToolbarHooks
- Toolbar hook implementations for announcements_feed.
Namespace
Drupal\announcements_feed\HookCode
public function toolbar() : array {
if (!$this->account
->hasPermission('access announcements')) {
return [
'#cache' => [
'contexts' => [
'user.permissions',
],
],
];
}
$items['announcement'] = [
'#type' => 'toolbar_item',
'tab' => [
'#lazy_builder' => [
'announcements_feed.lazy_builders:renderAnnouncements',
[],
],
'#create_placeholder' => TRUE,
'#cache' => [
'tags' => [
'announcements_feed:feed',
],
],
],
'#wrapper_attributes' => [
'class' => [
'announce-toolbar-tab',
],
],
'#cache' => [
'contexts' => [
'user.permissions',
],
],
'#weight' => 3399,
];
// \Drupal\toolbar\Element\ToolbarItem::preRenderToolbarItem adds an
// #attributes property to each toolbar item's tab child automatically. Lazy
// builders don't support an #attributes property so we need to add another
// render callback to remove the #attributes property. We start by adding
// the defaults, and then we append our own pre render callback.
$items['announcement'] += $this->elementInfoManager
->getInfo('toolbar_item');
$items['announcement']['#pre_render'][] = [
RenderCallbacks::class,
'removeTabAttributes',
];
return $items;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.