diff --git a/core/lib/Drupal/Core/Menu/MenuLinkBase.php b/core/lib/Drupal/Core/Menu/MenuLinkBase.php index 031b272..9796b84 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkBase.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkBase.php @@ -91,13 +91,6 @@ public function isExpanded() { /** * {@inheritdoc} */ - public function isDiscovered() { - return (bool) $this->pluginDefinition['discovered']; - } - - /** - * {@inheritdoc} - */ public function isResetable() { return FALSE; } diff --git a/core/lib/Drupal/Core/Menu/MenuLinkDefault.php b/core/lib/Drupal/Core/Menu/MenuLinkDefault.php index aea7b12..5cd52d2 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkDefault.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkDefault.php @@ -67,8 +67,8 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function isResetable() { - // The link can be reset if it was discovered and has an override. - return $this->pluginDefinition['discovered'] && $this->staticOverride->loadOverride($this->getPluginId()); + // The link can be reset if it has an override. + return $this->staticOverride->loadOverride($this->getPluginId()); } /** diff --git a/core/lib/Drupal/Core/Menu/MenuLinkInterface.php b/core/lib/Drupal/Core/Menu/MenuLinkInterface.php index 36d8520..64f99a2 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkInterface.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkInterface.php @@ -68,14 +68,6 @@ public function isHidden(); public function isExpanded(); /** - * Returns whether this link was discovered. - * - * @return bool - * TRUE if it is a discovered link, FALSE otherwise. - */ - public function isDiscovered(); - - /** * Returns whether this link can be reset. * * In general, only links that store overrides using the diff --git a/core/lib/Drupal/Core/Menu/MenuLinkManager.php b/core/lib/Drupal/Core/Menu/MenuLinkManager.php index ed51745..33521fc 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkManager.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkManager.php @@ -50,9 +50,7 @@ class MenuLinkManager implements MenuLinkManagerInterface { 'options' => array(), 'expanded' => 0, 'hidden' => 0, - // Flag for whether this plugin was discovered. Should be set to 0 or NULL - // for definitions that are added via a direct save. - 'discovered' => 0, + // The name of the module providing this link. 'provider' => '', 'metadata' => array(), // Default class for local task implementations. @@ -150,7 +148,7 @@ public function getDefinitions() { // Since this function is called rarely, instantiate the discovery here. $definitions = $this->getDiscovery()->getDefinitions(); - $this->moduleHandler->alter('menu_links', $definitions); + $this->moduleHandler->alter('menu_links_discovered', $definitions); foreach ($definitions as $plugin_id => &$definition) { $definition['id'] = $plugin_id; @@ -163,11 +161,6 @@ public function getDefinitions() { if (!empty($plugin_definition['provider']) && !$this->moduleHandler->moduleExists($plugin_definition['provider'])) { unset($definitions[$plugin_id]); } - else { - // Any link found here is flagged as discovered, so it can be purged - // if it does not exist in the future. - $definitions[$plugin_id]['discovered'] = 1; - } } return $definitions; } diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php index 89e0c80..003356c 100644 --- a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php +++ b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php @@ -87,7 +87,6 @@ class MenuTreeStorage implements MenuTreeStorageInterface { 'options', 'expanded', 'hidden', - 'discovered', 'provider', 'metadata', 'class', @@ -140,6 +139,8 @@ public function rebuild(array $definitions) { $before_menus = $this->getMenuNames(); if ($definitions) { foreach ($definitions as $id => $link) { + // Flag this link as discovered, i.e. saved via rebuild(). + $link['discovered'] = 1; if (!empty($link['parent'])) { $children[$link['parent']][$id] = $id; } diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorageInterface.php b/core/lib/Drupal/Core/Menu/MenuTreeStorageInterface.php index 5e7232d..0de1fe6 100644 --- a/core/lib/Drupal/Core/Menu/MenuTreeStorageInterface.php +++ b/core/lib/Drupal/Core/Menu/MenuTreeStorageInterface.php @@ -25,6 +25,10 @@ public function resetDefinitions(); /** * Rebuilds the stored menu link definitions. * + * Links that saved by passing definitions into this method must be included + * on all future calls, or they will be purged. This allows for automatic + * cleanup e.g. when modules are uninstalled. + * * @param array $definitions * The new menu link definitions. * diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 466b561..a738ddb 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -203,9 +203,9 @@ function content_translation_entity_operation_alter(array &$operations, \Drupal\ } /** - * Implements hook_menu_links_alter(). + * Implements hook_menu_links_discovered_alter(). */ -function content_translation_menu_links_alter(array &$links) { +function content_translation_menu_links_discovered_alter(array &$links) { // Clarify where translation settings are located. $links['language.content_settings_page']['title'] = 'Content language and translation'; $links['language.content_settings_page']['description'] = 'Configure language and translation support for content.'; diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index 3e18f0e..50b09e1 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -37,9 +37,9 @@ function dblog_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_menu_links_alter(). + * Implements hook_menu_links_discovered_alter(). */ -function dblog_menu_links_alter(&$links) { +function dblog_menu_links_discovered_alter(&$links) { if (\Drupal::moduleHandler()->moduleExists('search')) { $links['dblog.search'] = array( 'title' => 'Top search phrases', diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index 86fb63b..40c1eb7 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -40,12 +40,12 @@ function editor_help($route_name, RouteMatchInterface $route_match) { } /** - * Implements hook_menu_links_alter(). + * Implements hook_menu_links_discovered_alter(). * * Rewrites the menu entries for filter module that relate to the configuration * of text editors. */ -function editor_menu_links_alter(array &$links) { +function editor_menu_links_discovered_alter(array &$links) { $links['filter.admin_overview']['title'] = 'Text formats and editors'; $links['filter.admin_overview']['description'] = 'Configure how user-contributed content is filtered and formatted, as well as the text editor user interface (WYSIWYGs or toolbars).'; } diff --git a/core/modules/menu_ui/menu_ui.module b/core/modules/menu_ui/menu_ui.module index 0b57ffe..13596e3 100644 --- a/core/modules/menu_ui/menu_ui.module +++ b/core/modules/menu_ui/menu_ui.module @@ -100,23 +100,6 @@ function menu_ui_menu_insert(Menu $menu) { if (\Drupal::moduleHandler()->moduleExists('block')) { \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); } - - if ($menu->isSyncing()) { - return; - } - - // Make sure the menu is present in the active menus variable so that its - // items may appear in the menu active trail. - // See menu_set_active_menu_names(). - $config = \Drupal::config('system.menu'); - - $active_menus = $config->get('active_menus_default') ?: array_keys(menu_ui_get_menus()); - if (!in_array($menu->id(), $active_menus)) { - $active_menus[] = $menu->id(); - $config - ->set('active_menus_default', $active_menus) - ->save(); - } } /** @@ -138,19 +121,6 @@ function menu_ui_menu_predelete(Menu $menu) { /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */ $menu_link_manager = \Drupal::service('plugin.manager.menu.link'); $menu_link_manager->deleteLinksInMenu($menu->id()); - - // Remove menu from active menus variable. - $config = \Drupal::config('system.menu'); - $active_menus = $config->get('active_menus_default') ?: array_keys(menu_ui_get_menus()); - if (in_array($menu->id(), $active_menus)) { - $active_menus = array_diff($active_menus, array($menu->id())); - // Prevent the gap left by the removed menu from causing array indices to - // be saved. - $active_menus = array_values($active_menus); - $config - ->set('active_menus_default', $active_menus) - ->save(); - } } /** diff --git a/core/modules/system/config/install/system.menu.yml b/core/modules/system/config/install/system.menu.yml deleted file mode 100644 index e73636c..0000000 --- a/core/modules/system/config/install/system.menu.yml +++ /dev/null @@ -1 +0,0 @@ -active_menus_default: [] diff --git a/core/modules/system/config/schema/system.schema.yml b/core/modules/system/config/schema/system.schema.yml index 77e1382..f524376 100644 --- a/core/modules/system/config/schema/system.schema.yml +++ b/core/modules/system/config/schema/system.schema.yml @@ -168,17 +168,6 @@ system.logging: type: string label: 'Error messages to display' -system.menu: - type: mapping - label: 'Menu settings' - mapping: - active_menus_default: - type: sequence - label: 'Active menus' - sequence: - - type: string - label: 'Menu' - system.performance: type: mapping label: 'Performance settings' diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index cd3e79d..ef02d89 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -397,13 +397,13 @@ function hook_page_build(&$page) { } /** - * Alter links for menus. + * Alter all the menu links discovered by the menu link plugin manager. * * @param array $links * The link definitions to be altered. * * @return array - * An array of default menu links. Each link has a key that is the machine + * An array of discovered menu links. Each link has a key that is the machine * name, which must be unique. By default, use the route name as the * machine name. In cases where multiple links use the same route name, such * as two links to the same page in different menus, or two links using the @@ -440,7 +440,7 @@ function hook_page_build(&$page) { * * @ingroup menu */ -function hook_menu_links_alter(&$links) { +function hook_menu_links_discovered_alter(&$links) { // Change the weight and title of the user.logout link. $links['user.logout']['weight'] = -10; $links['user.logout']['title'] = 'Logout'; diff --git a/core/modules/system/tests/modules/menu_test/menu_test.module b/core/modules/system/tests/modules/menu_test/menu_test.module index 5299b0d..b4f76a2 100644 --- a/core/modules/system/tests/modules/menu_test/menu_test.module +++ b/core/modules/system/tests/modules/menu_test/menu_test.module @@ -6,9 +6,9 @@ */ /** - * Implements hook_menu_links_alter(). + * Implements hook_menu_links_discovered_alter(). */ -function menu_test_menu_links_alter(&$links) { +function menu_test_menu_links_discovered_alter(&$links) { // Many of the machine names here are slightly different from the route name. // Since the machine name is arbitrary, this helps ensure that core does not // add mistaken assumptions about the correlation.