diff --git a/core/modules/node/node.links.menu.yml b/core/modules/node/node.links.menu.yml index ae7a9af8c5..8b6ef4ac36 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 0000000000..27df952398 --- /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 0000000000..f288069bcf --- /dev/null +++ b/core/modules/node/src/Plugin/Menu/NodeMenuLink.php @@ -0,0 +1,10 @@ +systemManager->getBlockContents(); } + /** + * Provides a single block from the add content menu as a page + */ + public function systemAddMenuBlockPage() { + return $this->systemManager->getBlockContents(); + } + /** * Returns a theme listing. * diff --git a/core/modules/system/system.links.menu.yml b/core/modules/system/system.links.menu.yml index b5f9d87157..8a40e8890b 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 9cfe2ca54c..b6c91a4257 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 c7feaee237..54b53e890c 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; @@ -238,6 +273,25 @@ function toolbar_prerender_toolbar_administration_tray(array $element) { return $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. * diff --git a/core/themes/stable/css/toolbar/toolbar.icons.theme.css b/core/themes/stable/css/toolbar/toolbar.icons.theme.css index 2a0614ab3d..78aaf94797 100644 --- a/core/themes/stable/css/toolbar/toolbar.icons.theme.css +++ b/core/themes/stable/css/toolbar/toolbar.icons.theme.css @@ -85,6 +85,9 @@ .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(../../../../misc/icons/bebebe/plus.svg); +} /** * Main menu icons.