Commit 531fd593 authored by alexpott's avatar alexpott

Issue #2047633 by dawehner, pwolanin, Xano, amateescu, tim.plunkett: Move...

Issue #2047633 by dawehner, pwolanin, Xano, amateescu, tim.plunkett: Move definition of menu links to hook_menu_link_defaults(), decouple key name from path, and make 'parent' explicit.
parent 41330889
......@@ -1665,14 +1665,7 @@ function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
* The current page's title.
*/
function drupal_get_title() {
$title = drupal_set_title();
// During a bootstrap, menu.inc is not included and thus we cannot provide a title.
if (!isset($title) && function_exists('menu_get_active_title')) {
$title = String::checkPlain(menu_get_active_title());
}
return $title;
return drupal_set_title() ?: '';
}
/**
......
This diff is collapsed.
......@@ -5,6 +5,7 @@
* Functions to handle paths in Drupal.
*/
use Drupal\Core\Routing\RequestHelper;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -195,9 +196,23 @@ function drupal_valid_path($path, $dynamic_allowed = FALSE) {
global $menu_admin;
// We indicate that a menu administrator is running the menu access check.
$menu_admin = TRUE;
/** @var $route_provider \Drupal\Core\Routing\RouteProviderInterface */
$route_provider = \Drupal::service('router.route_provider');
if ($dynamic_allowed && preg_match('/\/\%/', $path)) {
$router_path = '/' . str_replace('%', '{}', $path);
}
else {
$router_path = $path;
}
if ($path == '<front>' || url_is_external($path)) {
$item = array('access' => TRUE);
}
elseif (($collection = $route_provider->getRoutesByPattern('/' . $router_path)) && $collection->count() > 0) {
$routes = $collection->all();
$route_name = key($routes);
}
elseif ($dynamic_allowed && preg_match('/\/\%/', $path)) {
// Path is dynamic (ie 'user/%'), so check directly against menu_router table.
if ($item = db_query("SELECT * FROM {menu_router} where path = :path", array(':path' => $path))->fetchAssoc()) {
......@@ -206,16 +221,22 @@ function drupal_valid_path($path, $dynamic_allowed = FALSE) {
$item['external'] = FALSE;
$item['options'] = '';
_menu_link_translate($item);
$route_name = $item['route_name'];
}
}
else {
$item = menu_get_item($path);
$route_name = $item['route_name'];
}
// Check the new routing system.
if (!empty($item['route_name'])) {
if (!empty($route_name)) {
$map = array();
$route = \Drupal::service('router.route_provider')->getRouteByName($item['route_name']);
$item['access'] = menu_item_route_access($route, $path, $map);
$route = \Drupal::service('router.route_provider')->getRouteByName($route_name);
$request = RequestHelper::duplicate(\Drupal::request(), '/' . $path);
$request->attributes->set('_system_path', $path);
$request->attributes->set('_menu_admin', TRUE);
$item['access'] = menu_item_route_access($route, $path, $map, $request);
}
$menu_admin = FALSE;
return $item && $item['access'];
......
......@@ -2137,6 +2137,14 @@ function template_preprocess_html(&$variables) {
'name' => String::checkPlain($site_config->get('name')),
);
}
// @todo Remove once views is not bypassing the view subscriber anymore.
// @see http://drupal.org/node/2068471
elseif (drupal_is_front_page()) {
$head_title = array(
'title' => t('Home'),
'name' => String::checkPlain($site_config->get('name')),
);
}
else {
$head_title = array('name' => String::checkPlain($site_config->get('name')));
if ($site_config->get('slogan')) {
......
......@@ -56,6 +56,20 @@ function action_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function action_menu_link_defaults() {
$links['action.admin.actions'] = 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_info().
*/
......
......@@ -127,6 +127,30 @@ function aggregator_menu() {
return $items;
}
/**
* 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',
'weight' => 10,
);
$links['aggregator'] = array(
'link_title' => 'Feed aggregator',
'weight' => 5,
'route_name' => 'aggregator.page_last',
);
$links['aggregator.sources'] = array(
'link_title' => 'Sources',
'route_name' => 'aggregator.sources',
);
return $links;
}
/**
* Implements hook_permission().
*/
......
......@@ -53,3 +53,18 @@ function ban_menu() {
);
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function ban_menu_link_defaults() {
$links['ban.admin.config.people'] = array(
'link_title' => 'IP address bans',
'description' => 'Manage banned IP addresses.',
'route_name' => 'ban.admin_page',
'weight' => 10,
'parent' => 'user.admin.config.people',
);
return $links;
}
......@@ -116,6 +116,20 @@ function block_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function block_menu_link_defaults() {
$links['block.admin.structure'] = array(
'link_title' => 'Blocks',
'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().
*
......
......@@ -180,6 +180,26 @@ function book_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function book_menu_link_defaults() {
$links['book.admin.outlines'] = array(
'link_title' => 'Books',
'description' => "Manage your site's book outlines.",
'parent' => 'system.admin.structure',
'route_name' => 'book.admin',
);
$links['book'] = 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;
}
/**
* Implements hook_admin_paths().
*/
......@@ -649,7 +669,7 @@ function template_preprocess_book_navigation(&$variables) {
$build = array();
if ($prev = book_prev($book_link)) {
$prev_href = url($prev['href']);
$prev_href = url($prev['link_path']);
$build['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'prev',
'href' => $prev_href,
......@@ -669,7 +689,7 @@ function template_preprocess_book_navigation(&$variables) {
}
if ($next = book_next($book_link)) {
$next_href = url($next['href']);
$next_href = url($next['link_path']);
$build['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'next',
'href' => $next_href,
......
......@@ -131,7 +131,7 @@ public function getLinkDefaults($nid) {
'menu_name' => '',
'nid' => $nid,
'bid' => 0,
'router_path' => 'node/%',
'link_path' => 'node/%',
'plid' => 0,
'mlid' => 0,
'has_children' => 0,
......@@ -211,7 +211,7 @@ public function addFormElements(array $form, array &$form_state, NodeInterface $
),
'#tree' => TRUE,
);
foreach (array('menu_name', 'mlid', 'nid', 'router_path', 'has_children', 'options', 'module', 'original_bid', 'parent_depth_limit') as $key) {
foreach (array('menu_name', 'mlid', 'nid', 'link_path', 'has_children', 'options', 'module', 'original_bid', 'parent_depth_limit') as $key) {
$form['book'][$key] = array(
'#type' => 'value',
'#value' => $node->book[$key],
......@@ -660,7 +660,7 @@ public function bookTreeOutput(array $tree) {
$element['#theme'] = 'menu_link__' . strtr($data['link']['menu_name'], '-', '_');
$element['#attributes']['class'] = $class;
$element['#title'] = $data['link']['title'];
$element['#href'] = $data['link']['href'];
$element['#href'] = $data['link']['link_path'];
$element['#localized_options'] = !empty($data['link']['localized_options']) ? $data['link']['localized_options'] : array();
$element['#below'] = $data['below'] ? $this->bookTreeOutput($data['below']) : $data['below'];
$element['#original_link'] = $data['link'];
......
......@@ -202,6 +202,20 @@ function comment_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function comment_menu_link_defaults() {
$links['comment.admin.content'] = array(
'link_title' => 'Comments',
'route_name' => 'comment.admin',
'parent' => 'node.admin.content',
'description' => 'List and edit site comments and the comment approval queue.',
);
return $links;
}
/**
* Implements hook_menu_alter().
*/
......
......@@ -69,3 +69,17 @@ function config_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function config_menu_link_defaults() {
$links['config.admin.management'] = array(
'link_title' => 'Configuration management',
'description' => 'Import, export, or synchronize your site configuration.',
'route_name' => 'config.sync',
'parent' => 'system.admin.config.development',
);
return $links;
}
......@@ -2,6 +2,7 @@ config_test.list_page:
path: '/admin/structure/config_test'
defaults:
_entity_list: 'config_test'
_title: 'Test configuration'
requirements:
_access: 'TRUE'
......
......@@ -45,6 +45,21 @@ function config_translation_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function config_translation_menu_link_defaults() {
$links['config_translation.admin.config-translation'] = 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().
*/
......
......@@ -79,6 +79,26 @@ function contact_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function contact_menu_link_defaults() {
$links['contact.admin.categories'] = 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'] = array(
'link_title' => 'Contact',
'route_name' => 'contact.site_page',
'menu_name' => 'footer',
'type' => MENU_SUGGESTED_ITEM,
);
return $links;
}
/**
* Implements hook_entity_bundle_info().
*/
......
......@@ -293,6 +293,15 @@ function content_translation_menu_alter(array &$items) {
}
}
/**
* Implements hook_menu_link_defaults_alter().
*/
function content_translation_menu_link_defaults_alter(array &$links) {
// Clarify where translation settings are located.
$items['admin.config.regional.language.content_settings_page']['link_title'] = 'Content language and translation';
$items['admin.config.regional.language.content_settings_page']['description'] = 'Configure language and translation support for content.';
}
/**
* Convert an entity canonical link to a router path.
*
......
......@@ -72,6 +72,42 @@ function dblog_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function dblog_menu_link_defaults() {
$links['dblog.admin.reports.dblog'] = 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.admin.reports.page-not-found'] = array(
'link_title' => "Top 'page not found' errors",
'route_name' => 'dblog.page_not_found',
'parent' => 'system.admin.reports',
'description' => "View 'page not found' errors (404s).",
);
$links['dblog.admin.reports.access-denied'] = array(
'link_title' => "Top 'access denied' errors",
'route_name' => 'dblog.access_denied',
'description' => "View 'access denied' errors (403s).",
'parent' => 'system.admin.reports',
);
if (\Drupal::moduleHandler()->moduleExists('search')) {
$links['dblog.admin.reports.search'] = array(
'link_title' => 'Top search phrases',
'route_name' => 'dblog.search',
'description' => 'View most popular search phrases.',
'parent' => 'system.admin.reports',
);
}
return $links;
}
/**
* Implements hook_page_build().
*/
......
......@@ -46,6 +46,14 @@ function editor_menu_alter(&$items) {
$items['admin/config/content/formats']['description'] = 'Configure how user-contributed content is filtered and formatted, as well as the text editor user interface (WYSIWYGs or toolbars).';
}
/**
* Implements hook_menu_link_defaults_alter().
*/
function editor_menu_link_defaults_alter(array &$links) {
$links['admin.config.content.formats']['link_title'] = 'Text formats and editors';
$links['admin.config.content.formats']['description'] = 'Configure how user-contributed content is filtered and formatted, as well as the text editor user interface (WYSIWYGs or toolbars).';
}
/**
* Implements hook_element_info().
*
......
......@@ -95,6 +95,36 @@ function entity_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function entity_menu_link_defaults() {
$links['entity.admin.structure.display_modes'] = array(
'link_title' => 'Display modes',
'description' => 'Configure what displays are available for your content and forms.',
'route_name' => 'entity.display_mode',
'parent' => 'system.admin.structure',
);
// View modes.
$links['entity.admin.structure.display_modes.view'] = array(
'link_title' => 'View modes',
'description' => 'Manage custom view modes.',
'route_name' => 'entity.view_mode_list',
'parent' => 'entity.admin.structure.display_modes',
);
// Form modes.
$links['entity.admin.structure.display_modes.form'] = array(
'link_title' => 'Form modes',
'description' => 'Manage custom form modes.',
'route_name' => 'entity.form_mode_list',
'parent' => 'entity.admin.structure.display_modes',
);
return $links;
}
/**
* Implements hook_entity_bundle_rename().
*/
......
......@@ -54,7 +54,7 @@ public function viewModeTypeSelection() {
if ($entity_info->isFieldable() && $entity_info->hasViewBuilderClass()) {
$entity_types[$entity_type] = array(
'title' => $entity_info->getLabel(),
'href' => 'admin/structure/display-modes/view/add/' . $entity_type,
'link_path' => 'admin/structure/display-modes/view/add/' . $entity_type,
'localized_options' => array(),
);
}
......@@ -77,7 +77,7 @@ public function formModeTypeSelection() {
if ($entity_info->isFieldable() && $entity_info->hasFormClasses()) {
$entity_types[$entity_type] = array(
'title' => $entity_info->getLabel(),
'href' => 'admin/structure/display-modes/form/add/' . $entity_type,
'link_path' => 'admin/structure/display-modes/form/add/' . $entity_type,
'localized_options' => array(),
);
}
......
......@@ -66,6 +66,20 @@ function field_ui_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function field_ui_menu_link_defaults() {
$links['field_ui.admin.reports.fields'] = array(
'link_title' => 'Field list',
'description' => 'Overview of fields on all entity types.',
'route_name' => 'field_ui.list',
'parent' => 'system.admin.reports',
);
return $links;
}
/**
* Implements hook_permission().
*/
......
......@@ -149,6 +149,26 @@ function filter_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function filter_menu_link_defaults() {
$links['filter.tips'] = array(
'link_title' => 'Compose tips',
'type' => MENU_SUGGESTED_ITEM,
'route_name' => 'filter.tips_all',
);
$links['filter.admin.formats'] = array(
'link_title' => 'Text formats',
'parent' => 'system.admin.config.content',
'description' => 'Configure how content input by users is filtered, including allowed HTML tags. Also allows enabling of module-provided filters.',
'route_name' => 'filter.admin_overview',
);
return $links;
}
/**
* Implements hook_permission().
*/
......
......@@ -131,6 +131,24 @@ function forum_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function forum_menu_link_defaults() {
$items['forum'] = array(
'link_title' => 'Forums',
'route_name' => 'forum.index',
'menu_name' => 'tools',
);
$items['forum.admin.overview'] = array(
'link_title' => 'Forums',
'parent' => 'system.admin.structure',
'description' => 'Control forum hierarchy settings.',
'route_name' => 'forum.overview',
);
return $items;
}
/**
* Implements hook_menu_local_tasks().
*/
......
......@@ -26,6 +26,7 @@ forum.page:
path: '/forum/{taxonomy_term}'
defaults:
_content: '\Drupal\forum\Controller\ForumController::forumPage'
_title_callback: '\Drupal\taxonomy\Controller\TaxonomyController::termTitle'
requirements:
_permission: 'access content'
......
......@@ -24,6 +24,21 @@ function help_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function help_menu_link_defaults() {
$links['help.main'] = array(
'link_title' => 'Help',
'description' => 'Reference for usage, configuration, and modules.',
'route_name' => 'help.main',
'weight' => 9,
'parent' => 'system.admin',
);
return $links;
}
/**
* Implements hook_help().
*/
......
......@@ -119,6 +119,20 @@ function image_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function image_menu_link_defaults() {
$links['image.admin.media.image-styles'] = array(
'link_title' => 'Image styles',
'description' => 'Configure styles that can be used for resizing or adjusting images on display.',
'parent' => 'system.admin.config.media',
'route_name' => 'image.style_list',
);
return $links;
}
/**
* Implements hook_theme().
*/
......
......@@ -90,6 +90,29 @@ function language_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function language_menu_link_defaults() {
// Base language management and configuration.
$links['language.admin.language.admin_overview'] = array(
'link_title' => 'Languages',
'description' => 'Configure languages for content and the user interface.',
'route_name' => 'language.admin_overview',
'parent' => 'system.admin.config.regional',
);
// Content language settings.
$links['language.admin.language.content_settings_page'] = array(
'link_title' => 'Content language',
'description' => 'Configure language support for content.',
'route_name' => 'language.content_settings_page',
'parent' => 'system.admin.config.regional',
'weight' => 10,
);
return $links;
}
/**
* Editing or deleting locked languages should not be possible.
*
......
......@@ -187,6 +187,29 @@ function locale_menu() {
return $items;
}
/**
* Implements hook_menu_link_defaults().
*/
function locale_menu_link_defaults() {
// Translation functionality.
$links['locale.admin.config.regional.translate'] = array(
'link_title' => 'User interface translation',
'description' => 'Translate the built-in user interface.',
'route_name' => 'locale.translate_page',
'parent' => 'system.admin.config.regional',
'weight' => 15,
);
$links['locale.admin.reports.translations'] = array(
'link_title' => 'Available translation updates',
'route_name' => 'locale.translate_status',
'description' => 'Get a status report about available interface translations for your installed modules and themes.',
'parent' => 'system.admin.reports',
);
return $links;
}
/**
* Implements hook_permission().
*/
......
......@@ -105,8 +105,8 @@ public function submit(array $form, array &$form_state) {
}
// Reset all the menu links defined by the system via hook_menu().
// @todo Convert this to an EFQ once we figure out 'ORDER BY m.number_parts'.
$result = $this->connection->query("SELECT mlid FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path = m.path WHERE ml.menu_name = :menu AND ml.module = 'system' ORDER BY m.number_parts ASC", array(':menu' => $this->entity->id()), array('fetch' => \PDO::FETCH_ASSOC))->fetchCol();
// @todo Convert this to an EFQ.
$result = $this->connection->query("SELECT mlid FROM {menu_links} WHERE menu_name = :menu AND module = 'system' ORDER BY depth ASC", array(':menu' => $this->entity->id()), array('fetch' => \PDO::FETCH_ASSOC))->fetchCol();
$menu_links = $this->storageController->loadMultiple($result);
foreach ($menu_links as $link) {
$link->reset();
......
......@@ -700,7 +700,7 @@ private function getStandardMenuLink() {
// the front page.
$query = \Drupal::entityQuery('menu_link')
->condition('module', 'system')
->condition('router_path', 'user/logout');
->condition('link_path', 'user/logout');
$result = $query->execute();
if (!empty($result)) {
$mlid = reset($result);
......
......@@ -14,12 +14,13 @@ function menu_install() {
// Add a link for each custom menu.
\Drupal::service('router.builder')->rebuild();