Commit 4ac79a13 authored by webchick's avatar webchick

Issue #2226903 by pwolanin, dawehner, tvn, martin107, jessebeach: Step 1: Move...

Issue #2226903 by pwolanin, dawehner, tvn, martin107, jessebeach: Step 1: Move static menu links to yml files.
parent 4a8bbfbb
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Drupal\Core\Template\Attribute; use Drupal\Core\Template\Attribute;
use Drupal\menu_link\MenuLinkInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Cmf\Component\Routing\RouteObjectInterface;
/** /**
...@@ -37,9 +36,9 @@ ...@@ -37,9 +36,9 @@
* the stuff in the routing.yml file means. * the stuff in the routing.yml file means.
* *
* @section Defining menu links * @section Defining menu links
* Once you have a route defined, you can use hook_menu_link_defaults() to * Once you have a route defined, you can use module.menu_links.yml to
* define links for your module's paths in the main Navigation menu or other * define links for your module's paths in the main Navigation menu or other
* menus. See the hook_menu_link_defaults() documentation for more details. * menus.
* *
* @todo The rest of this topic has not been reviewed or updated for Drupal 8.x * @todo The rest of this topic has not been reviewed or updated for Drupal 8.x
* and is not correct! * and is not correct!
...@@ -102,86 +101,6 @@ ...@@ -102,86 +101,6 @@
* add more with menu_link_save(). * add more with menu_link_save().
*/ */
/**
* @defgroup menu_flags Menu flags
* @{
* Flags for use in the "type" attribute of menu items.
*/
/**
* Internal menu flag -- menu item is the root of the menu tree.
*/
const MENU_IS_ROOT = 0x0001;
/**
* Internal menu flag -- menu item is visible in the menu tree.
*/
const MENU_VISIBLE_IN_TREE = 0x0002;
/**
* Internal menu flag -- menu item links back to its parent.
*/
const MENU_LINKS_TO_PARENT = 0x0008;
/**
* Internal menu flag -- menu item can be modified by administrator.
*/
const MENU_MODIFIED_BY_ADMIN = 0x0020;
/**
* Internal menu flag -- menu item was created by administrator.
*/
const MENU_CREATED_BY_ADMIN = 0x0040;
/**
* Internal menu flag -- menu item is a local task.
*/
const MENU_IS_LOCAL_TASK = 0x0080;
/**
* @} End of "defgroup menu_flags".
*/
/**
* @defgroup menu_item_types Menu item types
* @{
* Definitions for various menu item types.
*
* Menu item definitions provide one of these constants, which are shortcuts for
* combinations of @link menu_flags Menu flags @endlink.
*/
/**
* Menu type -- A "normal" menu item that's shown in menus.
*
* Normal menu items show up in the menu tree and can be moved/hidden by
* the administrator. Use this for most menu items. It is the default value if
* no menu item type is specified.
*/
define('MENU_NORMAL_ITEM', MENU_VISIBLE_IN_TREE);
/**
* Menu type -- A hidden, internal callback, typically used for API calls.
*
* Callbacks simply register a path so that the correct function is fired
* when the URL is accessed. They do not appear in menus.
*/
const MENU_CALLBACK = 0x0000;
/**
* Menu type -- A normal menu item, hidden until enabled by an administrator.
*
* Modules may "suggest" menu items that the administrator may enable. They act
* just as callbacks do until enabled, at which time they act like normal items.
* Note for the value: 0x0010 was a flag which is no longer used, but this way
* the values of MENU_CALLBACK and MENU_SUGGESTED_ITEM are separate.
*/
define('MENU_SUGGESTED_ITEM', 0x0010);
/**
* @} End of "defgroup menu_item_types".
*/
/** /**
* @defgroup menu_status_codes Menu status codes * @defgroup menu_status_codes Menu status codes
* @{ * @{
...@@ -998,24 +917,7 @@ function _menu_link_save_recursive($controller, $machine_name, &$children, &$lin ...@@ -998,24 +917,7 @@ function _menu_link_save_recursive($controller, $machine_name, &$children, &$lin
} }
/** /**
* Gets all default menu link definitions. * Builds menu links for the items returned from the menu_link.static service.
*
* @return array
* An array of default menu links.
*/
function menu_link_get_defaults() {
$module_handler = \Drupal::moduleHandler();
$all_links = $module_handler->invokeAll('menu_link_defaults');
// Fill in the machine name from the array key.
foreach ($all_links as $machine_name => &$link) {
$link['machine_name'] = $machine_name;
}
$module_handler->alter('menu_link_defaults', $all_links);
return $all_links;
}
/**
* Builds menu links for the items returned from hook_menu_link_defaults().
*/ */
function menu_link_rebuild_defaults() { function menu_link_rebuild_defaults() {
// Ensure that all configuration used to build the menu items are loaded // Ensure that all configuration used to build the menu items are loaded
...@@ -1034,7 +936,7 @@ function menu_link_rebuild_defaults() { ...@@ -1034,7 +936,7 @@ function menu_link_rebuild_defaults() {
$links = array(); $links = array();
$children = array(); $children = array();
$top_links = array(); $top_links = array();
$all_links = menu_link_get_defaults(); $all_links = \Drupal::service('menu_link.static')->getLinks();
if ($all_links) { if ($all_links) {
foreach ($all_links as $machine_name => $link) { foreach ($all_links as $machine_name => $link) {
// For performance reasons, do a straight query now and convert to a menu // For performance reasons, do a straight query now and convert to a menu
...@@ -1043,7 +945,6 @@ function menu_link_rebuild_defaults() { ...@@ -1043,7 +945,6 @@ function menu_link_rebuild_defaults() {
$existing_item = db_select('menu_links') $existing_item = db_select('menu_links')
->fields('menu_links') ->fields('menu_links')
->condition('machine_name', $machine_name) ->condition('machine_name', $machine_name)
->condition('module', 'system')
->execute()->fetchObject(); ->execute()->fetchObject();
if ($existing_item) { if ($existing_item) {
$existing_item->options = unserialize($existing_item->options); $existing_item->options = unserialize($existing_item->options);
...@@ -1060,7 +961,7 @@ function menu_link_rebuild_defaults() { ...@@ -1060,7 +961,7 @@ function menu_link_rebuild_defaults() {
$existing_item = $menu_link_storage->create(get_object_vars($existing_item)); $existing_item = $menu_link_storage->create(get_object_vars($existing_item));
if (!$existing_item->customized) { if (!$existing_item->customized) {
// A change in hook_menu_link_defaults() may move the link to a // A change in the default menu links may move the link to a
// different menu or parent. // different menu or parent.
if (!empty($link['menu_name']) && ($link['menu_name'] != $existing_item->menu_name)) { if (!empty($link['menu_name']) && ($link['menu_name'] != $existing_item->menu_name)) {
$menu_link->plid = NULL; $menu_link->plid = NULL;
...@@ -1108,7 +1009,7 @@ function menu_link_rebuild_defaults() { ...@@ -1108,7 +1009,7 @@ function menu_link_rebuild_defaults() {
} }
} }
// Find any item whose entry in hook_menu_link_defaults() no longer exists. // Find any item whose default menu link no longer exists.
if ($all_links) { if ($all_links) {
$query = \Drupal::entityQuery('menu_link') $query = \Drupal::entityQuery('menu_link')
->condition('machine_name', array_keys($all_links), 'NOT IN') ->condition('machine_name', array_keys($all_links), 'NOT IN')
......
action.admin:
title: Actions
description: 'Manage the actions defined for your site.'
route_name: action.admin
parent: system.admin_config_system
...@@ -44,20 +44,6 @@ function action_permission() { ...@@ -44,20 +44,6 @@ function action_permission() {
); );
} }
/**
* Implements hook_menu_link_defaults().
*/
function action_menu_link_defaults() {
$links['action.admin'] = array(
'link_title' => 'Actions',
'description' => 'Manage the actions defined for your site.',
'route_name' => 'action.admin',
'parent' => 'system.admin_config_system',
);
return $links;
}
/** /**
* Implements hook_entity_type_build(). * Implements hook_entity_type_build().
*/ */
......
aggregator.admin_overview:
title: 'Feed aggregator'
description: 'Configure which content your site aggregates from other sites, how often it polls them, and how they''re categorized.'
route_name: aggregator.admin_overview
parent: system.admin_config_services
weight: 10
aggregator.page_last:
title: 'Feed aggregator'
weight: 5
route_name: aggregator.page_last
aggregator.sources:
title: Sources
route_name: aggregator.sources
aggregator.feed_add:
title: 'Add feed'
route_name: aggregator.feed_add
...@@ -86,35 +86,6 @@ function aggregator_theme() { ...@@ -86,35 +86,6 @@ function aggregator_theme() {
); );
} }
/**
* Implements hook_menu_link_defaults().
*/
function aggregator_menu_link_defaults() {
$links = array();
$links['aggregator.admin_overview'] = array(
'link_title' => 'Feed aggregator',
'description' => "Configure which content your site aggregates from other sites, how often it polls them, and how they're categorized.",
'route_name' => 'aggregator.admin_overview',
'parent' => 'system.admin_config_services',
'weight' => 10,
);
$links['aggregator.page_last'] = array(
'link_title' => 'Feed aggregator',
'weight' => 5,
'route_name' => 'aggregator.page_last',
);
$links['aggregator.sources'] = array(
'link_title' => 'Sources',
'route_name' => 'aggregator.sources',
);
$links['aggregator.feed_add'] = array(
'link_title' => 'Add feed',
'route_name' => 'aggregator.feed_add',
);
return $links;
}
/** /**
* Implements hook_permission(). * Implements hook_permission().
*/ */
......
ban.admin_page:
title: 'IP address bans'
description: 'Manage banned IP addresses.'
route_name: ban.admin_page
weight: 10
parent: user.admin_index
...@@ -36,18 +36,3 @@ function ban_permission() { ...@@ -36,18 +36,3 @@ function ban_permission() {
), ),
); );
} }
/**
* Implements hook_menu_link_defaults().
*/
function ban_menu_link_defaults() {
$links['ban.admin_page'] = array(
'link_title' => 'IP address bans',
'description' => 'Manage banned IP addresses.',
'route_name' => 'ban.admin_page',
'weight' => 10,
'parent' => 'user.admin_index',
);
return $links;
}
block.admin_display:
title: 'Block layout'
parent: system.admin_structure
description: 'Configure what block content appears in your site''s sidebars and other regions.'
route_name: block.admin_display
...@@ -93,20 +93,6 @@ function block_permission() { ...@@ -93,20 +93,6 @@ function block_permission() {
); );
} }
/**
* Implements hook_menu_link_defaults().
*/
function block_menu_link_defaults() {
$links['block.admin_display'] = array(
'link_title' => 'Block layout',
'parent' => 'system.admin_structure',
'description' => 'Configure what block content appears in your site\'s sidebars and other regions.',
'route_name' => 'block.admin_display',
);
return $links;
}
/** /**
* Implements hook_page_build(). * Implements hook_page_build().
* *
......
book.admin:
title: Books
description: 'Manage your site''s book outlines.'
parent: system.admin_structure
route_name: book.admin
book.render:
title: Books
route_name: book.render
hidden: 1
...@@ -147,26 +147,6 @@ function book_node_links_alter(array &$node_links, NodeInterface $node, array &$ ...@@ -147,26 +147,6 @@ function book_node_links_alter(array &$node_links, NodeInterface $node, array &$
} }
} }
/**
* Implements hook_menu_link_defaults().
*/
function book_menu_link_defaults() {
$links['book.admin'] = array(
'link_title' => 'Books',
'description' => "Manage your site's book outlines.",
'parent' => 'system.admin_structure',
'route_name' => 'book.admin',
);
$links['book.render'] = array(
'link_title' => 'Books',
'route_name' => 'book.render',
// @todo what to do about MENU_SUGGESTED_ITEM, maybe specify no menu_name?
'type' => MENU_SUGGESTED_ITEM,
);
return $links;
}
/** /**
* Returns an array of all books. * Returns an array of all books.
* *
......
comment.admin:
title: Comments
route_name: comment.admin
parent: system.admin
description: 'List and edit site comments and the comment approval queue.'
comment.bundle_list:
title: 'Comment forms'
route_name: comment.bundle_list
parent: system.admin_structure
description: 'Manage fields and displays settings for comment forms.'
...@@ -164,26 +164,6 @@ function comment_theme() { ...@@ -164,26 +164,6 @@ function comment_theme() {
); );
} }
/**
* Implements hook_menu_link_defaults().
*/
function comment_menu_link_defaults() {
$links['comment.admin'] = array(
'link_title' => 'Comments',
'route_name' => 'comment.admin',
'parent' => \Drupal::moduleHandler()->moduleExists('node') ? 'node.content_overview' : 'system.admin',
'description' => 'List and edit site comments and the comment approval queue.',
);
$links['comment.bundle_list'] = array(
'link_title' => 'Comment forms',
'route_name' => 'comment.bundle_list',
'parent' => 'system.admin_structure',
'description' => 'Manage fields and displays settings for comment forms.',
);
return $links;
}
/** /**
* Implements hook_menu_link_defaults_alter() * Implements hook_menu_link_defaults_alter()
*/ */
...@@ -192,6 +172,9 @@ function comment_menu_link_defaults_alter(&$links) { ...@@ -192,6 +172,9 @@ function comment_menu_link_defaults_alter(&$links) {
// Add comments to the description for admin/content if any. // Add comments to the description for admin/content if any.
$links['node.content_overview']['description'] = 'Administer content and comments.'; $links['node.content_overview']['description'] = 'Administer content and comments.';
} }
if (\Drupal::moduleHandler()->moduleExists('node')) {
$links['comment.admin']['parent'] = 'node.content_overview';
}
} }
/** /**
......
config.sync:
title: 'Configuration management'
description: 'Import, export, or synchronize your site configuration.'
route_name: config.sync
parent: system.admin_config_development
...@@ -56,17 +56,3 @@ function config_file_download($uri) { ...@@ -56,17 +56,3 @@ function config_file_download($uri) {
); );
} }
} }
/**
* Implements hook_menu_link_defaults().
*/
function config_menu_link_defaults() {
$links['config.sync'] = array(
'link_title' => 'Configuration management',
'description' => 'Import, export, or synchronize your site configuration.',
'route_name' => 'config.sync',
'parent' => 'system.admin_config_development',
);
return $links;
}
config_translation.mapper_list:
title: 'Configuration translation'
parent: system.admin_config_regional
description: 'Translate the configuration.'
route_name: config_translation.mapper_list
weight: 30
...@@ -31,21 +31,6 @@ function config_translation_help($path) { ...@@ -31,21 +31,6 @@ function config_translation_help($path) {
} }
} }
/**
* Implements hook_menu_link_defaults().
*/
function config_translation_menu_link_defaults() {
$links['config_translation.mapper_list'] = array(
'link_title' => 'Configuration translation',
'parent' => 'system.admin_config_regional',
'description' => 'Translate the configuration.',
'route_name' => 'config_translation.mapper_list',
'weight' => 30,
);
return $links;
}
/** /**
* Implements hook_permission(). * Implements hook_permission().
*/ */
......
contact.category_list:
title: 'Contact form categories'
parent: system.admin_structure
description: 'Create a system contact form and set up categories for the form to use.'
route_name: contact.category_list
contact.site_page:
title: Contact
route_name: contact.site_page
menu_name: footer
hidden: 1
...@@ -51,26 +51,6 @@ function contact_permission() { ...@@ -51,26 +51,6 @@ function contact_permission() {
); );
} }
/**
* Implements hook_menu_link_defaults().
*/
function contact_menu_link_defaults() {
$links['contact.category_list'] = array(
'link_title' => 'Contact form categories',
'parent' => 'system.admin_structure',
'description' => 'Create a system contact form and set up categories for the form to use.',
'route_name' => 'contact.category_list',
);
$links['contact.site_page'] = array(
'link_title' => 'Contact',
'route_name' => 'contact.site_page',
'menu_name' => 'footer',
'type' => MENU_SUGGESTED_ITEM,
);
return $links;
}
/** /**
* Implements hook_entity_type_alter(). * Implements hook_entity_type_alter().
*/ */
......
...@@ -204,7 +204,7 @@ function content_translation_entity_operation_alter(array &$operations, \Drupal\ ...@@ -204,7 +204,7 @@ function content_translation_entity_operation_alter(array &$operations, \Drupal\
*/ */
function content_translation_menu_link_defaults_alter(array &$links) { function content_translation_menu_link_defaults_alter(array &$links) {
// Clarify where translation settings are located. // Clarify where translation settings are located.
$links['language.content_settings_page']['link_title'] = 'Content language and translation'; $links['language.content_settings_page']['title'] = 'Content language and translation';
$links['language.content_settings_page']['description'] = 'Configure language and translation support for content.'; $links['language.content_settings_page']['description'] = 'Configure language and translation support for content.';
} }
......
dblog.overview:
title: 'Recent log messages'
parent: system.admin_reports
description: 'View events that have recently been logged.'
route_name: dblog.overview
weight: -1
dblog.page_not_found:
title: 'Top ''page not found'' errors'
route_name: dblog.page_not_found
parent: system.admin_reports
description: 'View ''page not found'' errors (404s).'
dblog.access_denied:
title: 'Top ''access denied'' errors'
route_name: dblog.access_denied
description: 'View ''access denied'' errors (403s).'
parent: system.admin_reports
...@@ -36,32 +36,12 @@ function dblog_help($path, $arg) { ...@@ -36,32 +36,12 @@ function dblog_help($path, $arg) {
} }
/** /**
* Implements hook_menu_link_defaults(). * Implements hook_menu_link_defaults_alter().
*/ */
function dblog_menu_link_defaults() { function dblog_menu_link_defaults_alter(&$links) {
$links['dblog.overview'] = array(
'link_title' => 'Recent log messages',
'parent' => 'system.admin_reports',
'description' => 'View events that have recently been logged.',
'route_name' => 'dblog.overview',
'weight' => -1,
);
$links['dblog.page_not_found'] = array(
'link_title' => "Top 'page not found' errors",
'route_name' => 'dblog.page_not_found',
'parent' => 'system.admin_reports',