3 namespace Drupal\toolbar\Element;
5 use Drupal\Core\Render\Element\RenderElement;
9 * Provides a toolbar item that is wrapped in markup for common styling.
11 * The 'tray' property contains a renderable array.
13 * @RenderElement("toolbar_item")
15 class ToolbarItem extends RenderElement {
20 public function getInfo() {
21 $class = get_class($this);
24 [$class, 'preRenderToolbarItem'],
29 '#url' => Url::fromRoute('<front>'),
35 * Provides markup for associating a tray trigger with a tray element.
37 * A tray is a responsive container that wraps renderable content. Trays
38 * present content well on small and large screens alike.
40 * @param array $element
46 public static function preRenderToolbarItem($element) {
47 $id = $element['#id'];
49 // Provide attributes for a toolbar item.
54 // If tray content is present, markup the tray and its associated trigger.
55 if (!empty($element['tray'])) {
56 // Provide attributes necessary for trays.
58 'data-toolbar-tray' => $id . '-tray',
59 'aria-owns' => $id . '-tray',
61 'aria-pressed' => 'false',
64 // Merge in module-provided attributes.
65 $element['tab'] += ['#attributes' => []];
66 $element['tab']['#attributes'] += $attributes;
67 $element['tab']['#attributes']['class'][] = 'trigger';
69 // Provide attributes for the tray theme wrapper.
71 'id' => $id . '-tray',
72 'data-toolbar-tray' => $id . '-tray',
74 // Merge in module-provided attributes.
75 if (!isset($element['tray']['#wrapper_attributes'])) {
76 $element['tray']['#wrapper_attributes'] = [];
78 $element['tray']['#wrapper_attributes'] += $attributes;
79 $element['tray']['#wrapper_attributes']['class'][] = 'toolbar-tray';
82 $element['tab']['#attributes']['class'][] = 'toolbar-item';