ToolbarItem.php in Drupal 10
File
core/modules/toolbar/src/Element/ToolbarItem.php
View source
<?php
namespace Drupal\toolbar\Element;
use Drupal\Core\Render\Element\RenderElement;
use Drupal\Core\Url;
class ToolbarItem extends RenderElement {
public function getInfo() {
$class = static::class;
return [
'#pre_render' => [
[
$class,
'preRenderToolbarItem',
],
],
'tab' => [
'#type' => 'link',
'#title' => '',
'#url' => Url::fromRoute('<front>'),
],
];
}
public static function preRenderToolbarItem($element) {
$id = $element['#id'];
$attributes = [
'id' => $id,
];
if (!empty($element['tray'])) {
$attributes += [
'data-toolbar-tray' => $id . '-tray',
'role' => 'button',
'aria-pressed' => 'false',
];
$element['tab'] += [
'#attributes' => [],
];
$element['tab']['#attributes'] += $attributes;
$element['tab']['#attributes']['class'][] = 'trigger';
$attributes = [
'id' => $id . '-tray',
'data-toolbar-tray' => $id . '-tray',
];
if (!isset($element['tray']['#wrapper_attributes'])) {
$element['tray']['#wrapper_attributes'] = [];
}
$element['tray']['#wrapper_attributes'] += $attributes;
$element['tray']['#wrapper_attributes']['class'][] = 'toolbar-tray';
}
$element['tab']['#attributes']['class'][] = 'toolbar-item';
return $element;
}
}
Classes
Name |
Description |
ToolbarItem |
Provides a toolbar item that is wrapped in markup for common styling. |