I've successfully added an item to the the admin toolbar and now would like to create a drop down menu from that (i.e. the way Manage > Structure drops down Content Types, etc.)
This is how I've created the tray links ...
/**
* Implements hook_toolbar().
*/
function mymenu_toolbar() {
// Create the toolbar render array
$items['mymenu'] = [
'#type' => 'toolbar_item',
'tab' => [
'#type' => 'link',
'#title' => t('MyMenu'),
'#url' => Url::fromRoute('<front>'),
'#attributes' => [
'title' => t('MyMenu'),
'class' => ['toolbar-icon', 'toolbar-icon-mymenu'],
],
],
'tray' => [
'#heading' => t('MyMenu'),
'shortcuts' => [
'#theme' => 'links__toolbar_mymenu',
'#links' => [
['my_page_1'] = [
'title' => t('My Page 1'),
'url' => \Drupal\Core\Url::fromRoute('mymenu.mypage1'),
'attributes' => [
'title' => t('My Page 1 Description'),
],
],
['my_page_2'] = [
'title' => t('My Page 2'),
'url' => \Drupal\Core\Url::fromRoute('mymenu.mypage2'),
'attributes' => [
'title' => t('My Page 2 Description'),
],
],
],
'#attributes' => [
'class' => ['toolbar-menu'],
],
],
],
'#weight' => 999,
'#attached' => [
'library' => [
'mymenu/mymenu.icons',
],
],
];
return $items;
}
This produces ...
I thought perhaps adding my drop down items as children of the items in the #links array would work, but I haven't yet been able to work it out or find a good example of that being done.
Any suggestions?