diff --git a/core/modules/node/node.links.menu.yml b/core/modules/node/node.links.menu.yml index ae7a9af..8b6ef4a 100644 --- a/core/modules/node/node.links.menu.yml +++ b/core/modules/node/node.links.menu.yml @@ -4,5 +4,5 @@ entity.node_type.collection: description: 'Create and manage fields, forms, and display settings for your content.' route_name: entity.node_type.collection node.add_page: - title: 'Add content' - route_name: node.add_page + class: \Drupal\node\Plugin\Menu\NodeMenuLink + deriver: \Drupal\node\Plugin\Derivative\NodeMenuLinkDeriver diff --git a/core/modules/node/src/Plugin/Derivative/NodeMenuLinkDeriver.php b/core/modules/node/src/Plugin/Derivative/NodeMenuLinkDeriver.php new file mode 100644 index 0000000..27df952 --- /dev/null +++ b/core/modules/node/src/Plugin/Derivative/NodeMenuLinkDeriver.php @@ -0,0 +1,60 @@ +entityStorage = $entity_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, $base_plugin_id) { + return new static( + $base_plugin_id, + $container->get('entity_type.manager')->getStorage('node_type') + ); + } + + /** + * {@inheritdoc} + */ + public function getDerivativeDefinitions($base_plugin_definition) { + $links = []; + $bundles = $this->entityStorage->loadMultiple(); + + foreach ($bundles as $id => $bundle) { + $links[$id] = [ + 'title' => $bundle->label(), + 'parent' => 'system.add', + 'route_name' => 'node.add', + 'route_parameters' => ['node_type' => $id], + ] + $base_plugin_definition; + } + + return $links; + } +} diff --git a/core/modules/node/src/Plugin/Menu/NodeMenuLink.php b/core/modules/node/src/Plugin/Menu/NodeMenuLink.php new file mode 100644 index 0000000..f288069 --- /dev/null +++ b/core/modules/node/src/Plugin/Menu/NodeMenuLink.php @@ -0,0 +1,10 @@ +systemManager->getBlockContents(); + } + + /** * Returns a theme listing. * * @return string diff --git a/core/modules/system/system.links.menu.yml b/core/modules/system/system.links.menu.yml index b5f9d87..8a40e88 100644 --- a/core/modules/system/system.links.menu.yml +++ b/core/modules/system/system.links.menu.yml @@ -3,6 +3,11 @@ system.admin: route_name: system.admin weight: 9 menu_name: admin +system.add: + title: 'Add any content' + route_name: system.add + weight: 10 + menu_name: add system.admin_content: title: Content description: 'Find and manage content.' diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index 9cfe2ca..b6c91a4 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -38,6 +38,14 @@ system.admin: requirements: _permission: 'access administration pages' +system.add: + path: '/add' + defaults: + _controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage' + _title: 'Add any content' + requirements: + _permission: 'access administration pages' + system.admin_structure: path: '/admin/structure' defaults: diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index c7feaee..54b53e8 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -203,6 +203,41 @@ function toolbar_toolbar() { ], '#weight' => -15, ]; + + // The add element has a tray with the Add content menu. + $items['add'] = [ + '#type' => 'toolbar_item', + 'tab' => [ + '#type' => 'link', + '#title' => t('Add'), + '#url' => Url::fromRoute('system.add'), + '#attributes' => [ + 'title' => t('Add content menu'), + 'class' => ['toolbar-icon', 'toolbar-icon-add'], + // A data attribute that indicates to the client to defer loading of + // the admin menu subtrees until this tab is activated. Admin menu + // subtrees will not render to the DOM if this attribute is removed. + // The value of the attribute is intentionally left blank. Only the + // presence of the attribute is necessary. + 'data-drupal-subtrees' => '', + ], + ], + 'tray' => [ + '#heading' => t('Add content menu'), + '#attached' => $subtrees_attached, + 'toolbar_administration' => [ + '#pre_render' => [ + 'toolbar_prerender_toolbar_add_tray', + ], + '#type' => 'container', + '#attributes' => [ + 'class' => ['toolbar-menu-administration'], + ], + ], + ], + '#weight' => -14, + ]; + $hash_cacheability->applyTo($items['administration']); return $items; @@ -239,6 +274,25 @@ function toolbar_prerender_toolbar_administration_tray(array $element) { } /** + * Renders the toolbar's Add content tray + * in the same way as the Administration tray + */ +function toolbar_prerender_toolbar_add_tray(array $element) { + $menu_tree = \Drupal::service('toolbar.menu_tree'); + $parameters = new MenuTreeParameters(); + $parameters->setMinDepth(2)->setMaxDepth(2)->onlyEnabledLinks(); + $tree = $menu_tree->load('add', $parameters); + $manipulators = [ + ['callable' => 'menu.default_tree_manipulators:checkAccess'], + ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'], + ['callable' => 'toolbar_menu_navigation_links'], + ]; + $tree = $menu_tree->transform($tree, $manipulators); + $element['administration_menu'] = $menu_tree->build($tree); + return $element; +} + +/** * Adds toolbar-specific attributes to the menu link tree. * * @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree diff --git a/core/profiles/demo_umami/demo_umami.install b/core/profiles/demo_umami/demo_umami.install index b3c1bfe..867067d 100644 --- a/core/profiles/demo_umami/demo_umami.install +++ b/core/profiles/demo_umami/demo_umami.install @@ -75,14 +75,6 @@ function demo_umami_install() { // Populate the default shortcut set. $shortcut = Shortcut::create([ 'shortcut_set' => 'default', - 'title' => t('Add content'), - 'weight' => -20, - 'link' => ['uri' => 'internal:/node/add'], - ]); - $shortcut->save(); - - $shortcut = Shortcut::create([ - 'shortcut_set' => 'default', 'title' => t('All content'), 'weight' => -19, 'link' => ['uri' => 'internal:/admin/content'], diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index 2f567ab..45570fb 100644 --- a/core/profiles/standard/standard.install +++ b/core/profiles/standard/standard.install @@ -51,14 +51,6 @@ function standard_install() { // Populate the default shortcut set. $shortcut = Shortcut::create([ 'shortcut_set' => 'default', - 'title' => t('Add content'), - 'weight' => -20, - 'link' => ['uri' => 'internal:/node/add'], - ]); - $shortcut->save(); - - $shortcut = Shortcut::create([ - 'shortcut_set' => 'default', 'title' => t('All content'), 'weight' => -19, 'link' => ['uri' => 'internal:/admin/content'], diff --git a/core/themes/stable/css/toolbar/toolbar.icons.theme.css b/core/themes/stable/css/toolbar/toolbar.icons.theme.css index 2a0614a..aae873b 100644 --- a/core/themes/stable/css/toolbar/toolbar.icons.theme.css +++ b/core/themes/stable/css/toolbar/toolbar.icons.theme.css @@ -85,6 +85,13 @@ .toolbar-bar .toolbar-icon-help.is-active:before { background-image: url(../../images/core/icons/ffffff/questionmark-disc.svg); } +.toolbar-bar .toolbar-icon-add:before { + background-image: url(../../images/core/icons/bebebe/plus.svg); +} +.toolbar-bar .toolbar-icon-add:active:before, +.toolbar-bar .toolbar-icon-add.is-active:before { + background-image: url(../../images/core/icons/ffffff/plus.svg); +} /** * Main menu icons. diff --git a/core/themes/stable/images/core/icons/bebebe/plus.svg b/core/themes/stable/images/core/icons/bebebe/plus.svg new file mode 100644 index 0000000..5006648 --- /dev/null +++ b/core/themes/stable/images/core/icons/bebebe/plus.svg @@ -0,0 +1 @@ + diff --git a/core/themes/stable/images/core/icons/ffffff/plus.svg b/core/themes/stable/images/core/icons/ffffff/plus.svg new file mode 100644 index 0000000..dace50e --- /dev/null +++ b/core/themes/stable/images/core/icons/ffffff/plus.svg @@ -0,0 +1,55 @@ + + + + + + image/svg+xml + + + + + + + + +