diff --git a/core/includes/menu.inc b/core/includes/menu.inc index d205ac0..ccc40f8 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -895,7 +895,6 @@ function _menu_link_translate(&$item, $translate = FALSE) { // current path, and we can take over the argument map for a link like // 'foo/%/bar'. This inheritance is only valid for breadcrumb links. // @see _menu_tree_check_access() - // @see menu_get_active_breadcrumb() elseif ($translate && ($current_router_item = menu_get_item())) { // If $translate is TRUE, then this link is in the active trail. // Only translate paths within the current path. @@ -2610,57 +2609,6 @@ function menu_get_active_trail() { } /** - * Gets the breadcrumb for the current page, as determined by the active trail. - * - * @see menu_set_active_trail() - */ -function menu_get_active_breadcrumb() { - $breadcrumb = array(); - - // No breadcrumb for the front page. - if (drupal_is_front_page()) { - return $breadcrumb; - } - - $item = menu_get_item(); - if (!empty($item['access'])) { - $active_trail = menu_get_active_trail(); - - // Allow modules to alter the breadcrumb, if possible, as that is much - // faster than rebuilding an entirely new active trail. - drupal_alter('menu_breadcrumb', $active_trail, $item); - - // Don't show a link to the current page in the breadcrumb trail. - $end = end($active_trail); - if (Drupal::request()->attributes->get('_system_path') == $end['href']) { - array_pop($active_trail); - } - - // Remove the tab root (parent) if the current path links to its parent. - // Normally, the tab root link is included in the breadcrumb, as soon as we - // are on a local task or any other child link. However, if we are on a - // default local task (e.g., node/%/view), then we do not want the tab root - // link (e.g., node/%) to appear, as it would be identical to the current - // page. Since this behavior also needs to work recursively (i.e., on - // default local tasks of default local tasks), and since the last non-task - // link in the trail is used as page title (see menu_get_active_title()), - // this condition cannot be cleanly integrated into menu_get_active_trail(). - // menu_get_active_trail() already skips all links that link to their parent - // (commonly MENU_DEFAULT_LOCAL_TASK). In order to also hide the parent link - // itself, we always remove the last link in the trail, if the current - // router item links to its parent. - if (($item['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT) { - array_pop($active_trail); - } - - foreach ($active_trail as $parent) { - $breadcrumb[] = l($parent['title'], $parent['href'], $parent['localized_options']); - } - } - return $breadcrumb; -} - -/** * Gets the title of the current page, as determined by the active trail. */ function menu_get_active_title() { diff --git a/core/modules/book/book.services.yml b/core/modules/book/book.services.yml index 9d8c140..283efd8 100644 --- a/core/modules/book/book.services.yml +++ b/core/modules/book/book.services.yml @@ -1,4 +1,9 @@ services: + book.breadcrumb: + class: Drupal\book\BookBreadcrumbBuilder + arguments: ['@plugin.manager.entity', '@access_manager', '@string_translation'] + tags: + - { name: breadcrumb_builder, priority: 701 } book.manager: class: Drupal\book\BookManager arguments: ['@database', '@plugin.manager.entity'] diff --git a/core/modules/book/lib/Drupal/book/BookBreadcrumbBuilder.php b/core/modules/book/lib/Drupal/book/BookBreadcrumbBuilder.php new file mode 100644 index 0000000..80838bc --- /dev/null +++ b/core/modules/book/lib/Drupal/book/BookBreadcrumbBuilder.php @@ -0,0 +1,107 @@ +menuLinkStorage = $entity_manager->getStorageController('menu_link'); + $this->accessManager = $access_manager; + $this->translation = $translation; + } + + /** + * {@inheritdoc} + */ + public function build(array $attributes) { + // @todo - like \Drupal\forum\ForumBreadcrumbBuilder this depends on the + // legacy non-route node view. It must be updated once that's converted. + if (!empty($attributes['_drupal_menu_item']) && !empty($attributes['_drupal_menu_item']['map'][1]->book)) { + $mlids = array(); + // @todo Replace with link generator service when + // https://drupal.org/node/2047619 lands. + $links = array(l($this->translation->translate('Home'), '')); + $book = $attributes['_drupal_menu_item']['map'][1]->book; + $depth = 1; + // We skip the current node. + while (!empty($book['p' . ($depth + 1)])) { + $mlids[] = $book['p' . $depth]; + $depth++; + } + $menu_links = $this->menuLinkStorage->loadMultiple($mlids); + if (count($menu_links) > 0) { + $depth = 1; + while (!empty($book['p' . ($depth + 1)])) { + if (!empty($menu_links[$book['p' . $depth]]) && ($menu_link = $menu_links[$book['p' . $depth]])) { + // Legacy hook_menu page callback. + // @todo change this once thie node view route is converted. + if ($item = menu_get_item($menu_link->link_path)) { + if ($item['access']) { + $links[] = l($menu_link->label(), $menu_link->link_path, $menu_link->options); + } + } + } + $depth++; + } + } + return $links; + } + } + +} diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php index e994202..b841d70 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php @@ -81,7 +81,10 @@ public function routes(RouteBuildEvent $event) { } $route = new Route( "$path/fields", - array('_form' => '\Drupal\field_ui\FieldOverview') + $defaults, + array( + '_form' => '\Drupal\field_ui\FieldOverview', + '_title' => t('Manage fields'), + ) + $defaults, array('_permission' => 'administer ' . $entity_type . ' fields') ); $collection->add("field_ui.overview.$entity_type", $route); @@ -106,7 +109,10 @@ public function routes(RouteBuildEvent $event) { $route = new Route( "$path/display", - array('_form' => '\Drupal\field_ui\DisplayOverview') + $defaults, + array( + '_form' => '\Drupal\field_ui\DisplayOverview', + '_title' => t('Manage display'), + ) + $defaults, array('_permission' => 'administer ' . $entity_type . ' display') ); $collection->add("field_ui.display_overview.$entity_type", $route); diff --git a/core/modules/filter/filter.routing.yml b/core/modules/filter/filter.routing.yml index 5442fb0..8d90694 100644 --- a/core/modules/filter/filter.routing.yml +++ b/core/modules/filter/filter.routing.yml @@ -17,6 +17,7 @@ filter_admin_overview: defaults: _content: '\Drupal\Core\Entity\Controller\EntityListController::listing' entity_type: 'filter_format' + _title: 'Text formats and editors' requirements: _permission: 'administer filters' diff --git a/core/modules/image/lib/Drupal/image/PathProcessor/PathProcessorImageStyles.php b/core/modules/image/lib/Drupal/image/PathProcessor/PathProcessorImageStyles.php index c0c6f31..4418476 100644 --- a/core/modules/image/lib/Drupal/image/PathProcessor/PathProcessorImageStyles.php +++ b/core/modules/image/lib/Drupal/image/PathProcessor/PathProcessorImageStyles.php @@ -46,12 +46,17 @@ public function processInbound($path, Request $request) { $rest = preg_replace('|^' . $path_prefix . '|', '', $path); // Get the image style, scheme and path. - list($image_style, $scheme, $file) = explode('/', $rest, 3); + if (substr_count($rest, '/') >= 2) { + list($image_style, $scheme, $file) = explode('/', $rest, 3); - // Set the file as query parameter. - $request->query->set('file', $file); + // Set the file as query parameter. + $request->query->set('file', $file); - return $path_prefix . $image_style . '/' . $scheme; + return $path_prefix . $image_style . '/' . $scheme; + } + else { + return $path; + } } } diff --git a/core/modules/menu/menu.routing.yml b/core/modules/menu/menu.routing.yml index c5a0d10..dc1b4a0 100644 --- a/core/modules/menu/menu.routing.yml +++ b/core/modules/menu/menu.routing.yml @@ -9,6 +9,7 @@ menu_overview_page: pattern: '/admin/structure/menu' defaults: _entity_list: 'menu' + _title: 'Menus' requirements: _permission: 'administer menu' diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php deleted file mode 100644 index acece08..0000000 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php +++ /dev/null @@ -1,26 +0,0 @@ -isNew()) { - // Get the human-readable menu title from the given menu name. - $titles = menu_get_menus(); - $current_title = $titles[$menu_link->menu_name]; - - // Get the current breadcrumb and add a link to that menu's overview page. - $breadcrumb = menu_get_active_breadcrumb(); - $breadcrumb[] = l($current_title, 'admin/structure/menu/manage/' . $menu_link->menu_name); - drupal_set_breadcrumb($breadcrumb); - } - $form['link_title'] = array( '#type' => 'textfield', '#title' => t('Menu link title'), diff --git a/core/modules/menu_link/menu_link.services.yml b/core/modules/menu_link/menu_link.services.yml deleted file mode 100644 index a428476..0000000 --- a/core/modules/menu_link/menu_link.services.yml +++ /dev/null @@ -1,5 +0,0 @@ -services: - menu_link.breadcrumb: - class: Drupal\menu_link\MenuLinkBreadcrumbBuilder - tags: - - { name: breadcrumb_builder, priority: 0 } diff --git a/core/modules/node/node.routing.yml b/core/modules/node/node.routing.yml index dfdc0a6..0b254d6 100644 --- a/core/modules/node/node.routing.yml +++ b/core/modules/node/node.routing.yml @@ -38,6 +38,7 @@ node_overview_types: defaults: _content: '\Drupal\Core\Entity\Controller\EntityListController::listing' entity_type: 'node_type' + _title: 'Content types' requirements: _permission: 'administer content types' diff --git a/core/modules/system/lib/Drupal/system/PathBasedBreadcrumbBuilder.php b/core/modules/system/lib/Drupal/system/PathBasedBreadcrumbBuilder.php new file mode 100644 index 0000000..247a385 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/PathBasedBreadcrumbBuilder.php @@ -0,0 +1,199 @@ +request = $request; + $this->accessManager = $access_manager; + $this->translation = $translation; + $this->menuStorage = $entity_manager->getStorageController('menu'); + $this->router = $router; + $this->pathProcessor = $path_processor; + $this->config = $config_factory->get('system.site'); + } + + /** + * {@inheritdoc} + */ + public function build(array $attributes) { + $links = array(); + + // Custom breadcrumb behaviour for editing menu links, we append a link to + // the menu in which the link is found. + if (!empty($attributes['_route']) && $attributes['_route'] == 'menu_link_edit' && !empty($attributes['menu_link'])) { + $menu_link = $attributes['menu_link']; + if (!$menu_link->isNew()) { + // Add a link to the menu admin screen. + $menu = $this->menuStorage->load($menu_link->menu_name); + $links[] = l($menu->label(), 'admin/structure/menu/manage/' . $menu_link->menu_name); + } + } + + // General path-based breadcrumbs. Use the original, aliased path. + $path = trim($this->request->getPathInfo(), '/'); + $path_elements = explode('/', $path); + $front = $this->config->get('page.front'); + while (count($path_elements) > 1) { + array_pop($path_elements); + // Copy the path elements for up-casting. + $pattern = implode('/', $path_elements); + if ($pattern == $front) { + // Don't show a link to the front-page path. + continue; + } + $route_request = $this->getRequestForPath($pattern); + if ($route_request) { + $access = FALSE; + // @todo - remove this once all of core is converted to the new router. + if ($route_request->attributes->get('_legacy')) { + $menu_item = $route_request->attributes->get('_drupal_menu_item'); + if (($menu_item['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT) { + continue; + } + $access = $menu_item['access']; + $title = $menu_item['title']; + } + else { + $route_name = $route_request->attributes->get(RouteObjectInterface::ROUTE_NAME); + // Note that the parameters don't really matter here since we're + // passing in the request which already has the upcast attributes. + $parameters = array(); + $access = $this->accessManager->checkNamedRoute($route_name, $parameters, $route_request); + $title = $route_request->attributes->get('_title'); + } + if ($access) { + if (!$title) { + // @todo Revisit when + $title = str_replace(array('-', '_'), ' ', Unicode::ucfirst(end($path_elements))); + } + // @todo Replace with a #type => link render element when + // https://drupal.org/node/2047619 lands. + $links[] = l($title, $route_request->attributes->get('_system_path')); + } + } + + } + // @todo Replace with a #type => link render element when + // https://drupal.org/node/2047619 lands. + if ($path && $path != $front) { + // Add the Home link, except for the front page. + $links[] = l($this->translation->translate('Home'), ''); + } + return array_reverse($links); + } + + /** + * Matches a path in the router. + * + * @param string $path + * The request path. + * + * @return \Symfony\Component\HttpFoundation\Request + * A populated request object or NULL if the patch couldn't be matched. + */ + protected function getRequestForPath($path) { + $request = Request::create($path); + $processed = $this->pathProcessor->processInbound($path, $request); + $request->attributes->set('_system_path', $processed); + // Attempt to match this path to provide a fully built request. + try { + $request->attributes->add($this->router->matchRequest($request)); + return $request; + } + catch (NotFoundHttpException $e) { + return NULL; + } + catch (ResourceNotFoundException $e) { + return NULL; + } + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php index 7d1814e..d3c62cc 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php @@ -8,6 +8,7 @@ namespace Drupal\system\Tests\Menu; use Drupal\Core\Language\Language; +use Drupal\Component\Utility\Unicode; /** * Menu breadcrumbs related tests. @@ -60,33 +61,12 @@ function testBreadCrumbs() { // Prepare common base breadcrumb elements. $home = array('' => 'Home'); $admin = $home + array('admin' => t('Administration')); - $config = $admin + array('admin/config' => t('Configuration')); + // @todo Revert to 'Configuration' when https://drupal.org/node/2075701 is + // in. + $config = $admin + array('admin/config' => t('Config')); $type = 'article'; $langcode = Language::LANGCODE_NOT_SPECIFIED; - // Verify breadcrumbs for default local tasks. - $expected = array( - 'menu-test' => t('Menu test root'), - ); - $title = t('Breadcrumbs test: Local tasks'); - $trail = $home + $expected; - $tree = $expected + array( - 'menu-test/breadcrumb/tasks' => $title, - ); - $this->assertBreadcrumb('menu-test/breadcrumb/tasks', $trail, $title, $tree); - $this->assertBreadcrumb('menu-test/breadcrumb/tasks/first', $trail, $title, $tree); - $this->assertBreadcrumb('menu-test/breadcrumb/tasks/first/first', $trail, $title, $tree); - $trail += array( - 'menu-test/breadcrumb/tasks' => t('Breadcrumbs test: Local tasks'), - ); - $this->assertBreadcrumb('menu-test/breadcrumb/tasks/first/second', $trail, $title, $tree); - $this->assertBreadcrumb('menu-test/breadcrumb/tasks/second', $trail, $title, $tree); - $this->assertBreadcrumb('menu-test/breadcrumb/tasks/second/first', $trail, $title, $tree); - $trail += array( - 'menu-test/breadcrumb/tasks/second' => t('Second'), - ); - $this->assertBreadcrumb('menu-test/breadcrumb/tasks/second/second', $trail, $title, $tree); - // Verify Taxonomy administration breadcrumbs. $trail = $admin + array( 'admin/structure' => t('Structure'), @@ -164,7 +144,7 @@ function testBreadCrumbs() { $this->assertBreadcrumb('admin/config/content/formats/add', $trail); $this->assertBreadcrumb("admin/config/content/formats/manage/$format_id", $trail); $trail += array( - "admin/config/content/formats/manage/$format_id" => $format->name, + "admin/config/content/formats/manage/$format_id" => Unicode::ucfirst(Unicode::strtolower($format->name)), ); $this->assertBreadcrumb("admin/config/content/formats/manage/$format_id/disable", $trail); @@ -288,14 +268,12 @@ function testBreadCrumbs() { $tree = $expected + array( 'node/' . $parent->id() => $parent->menu['link_title'], ); - $this->assertBreadcrumb(NULL, $trail, $parent->getTitle(), $tree); $trail += array( 'node/' . $parent->id() => $parent->menu['link_title'], ); $tree += array( 'node/' . $parent->id() => $child->menu['link_title'], ); - $this->assertBreadcrumb('node/' . $child->id(), $trail, $child->getTitle(), $tree); // Add a taxonomy term/tag to last node, and add a link for that term to the // Tools menu. diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuTranslateTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuTranslateTest.php index 33aa51a..8c27287 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/MenuTranslateTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/MenuTranslateTest.php @@ -45,7 +45,11 @@ public function testMenuTranslate() { // Attempt to access a restricted local task. $this->drupalGet('foo/asdf/c'); $this->assertResponse(403); - $this->assertNoLinkByHref('foo/asdf'); + $elements = $this->xpath('//ul[@class=:class]/li/a[@href=:href]', array( + ':class' => 'tabs primary', + ':href' => url('foo/asdf'), + )); + $this->assertTrue(empty($elements), 'No tab linking to foo/asdf found'); $this->assertNoLinkByHref('foo/asdf/b'); $this->assertNoLinkByHref('foo/asdf/c'); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/TrailTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/TrailTest.php index fbd3e34..4da001e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/TrailTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/TrailTest.php @@ -83,23 +83,9 @@ function testMenuTreeSetPath() { 'admin/config/development/menu-trail' => t('Menu trail - Case 2'), ); - $override_breadcrumb = $config + array( - 'admin/config/system' => t('System'), - 'admin/config/system/site-information' => t('Site information'), - ); - $override_tree = $config_tree + array( - 'admin/config/system' => t('System'), - 'admin/config/system/site-information' => t('Site information'), - ); - // Test the tree generation for the Administration menu. \Drupal::state()->delete('menu_test.menu_tree_set_path'); $this->assertBreadcrumb('admin/config/development/menu-trail', $breadcrumb, t('Menu trail - Case 2'), $tree); - - // Override the active trail for the Administration tree; it should affect - // the breadcrumbs and Administration tree. - \Drupal::state()->set('menu_test.menu_tree_set_path', $test_menu_path); - $this->assertBreadcrumb('admin/config/development/menu-trail', $override_breadcrumb, t('Menu trail - Case 2'), $override_tree); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/TreeAccessTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/TreeAccessTest.php index 263e2fc..df10877 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/TreeAccessTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/TreeAccessTest.php @@ -33,6 +33,13 @@ class TreeAccessTest extends DrupalUnitTestBase { */ protected $routeCollection; + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('menu_link'); + public static function getInfo() { return array( 'name' => 'Menu tree access', diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 6339d1c..4d7aae0 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -940,53 +940,6 @@ function hook_local_task_alter(&$local_tasks) { } /** - * Alter links in the active trail before it is rendered as the breadcrumb. - * - * This hook is invoked by menu_get_active_breadcrumb() and allows alteration - * of the breadcrumb links for the current page, which may be preferred instead - * of setting a custom breadcrumb via drupal_set_breadcrumb(). - * - * Implementations should take into account that menu_get_active_breadcrumb() - * subsequently performs the following adjustments to the active trail *after* - * this hook has been invoked: - * - The last link in $active_trail is removed, if its 'href' is identical to - * the 'href' of $item. This happens, because the breadcrumb normally does - * not contain a link to the current page. - * - The (second to) last link in $active_trail is removed, if the current $item - * is a MENU_DEFAULT_LOCAL_TASK. This happens in order to do not show a link - * to the current page, when being on the path for the default local task; - * e.g. when being on the path node/%/view, the breadcrumb should not contain - * a link to node/%. - * - * Each link in the active trail must contain: - * - title: The localized title of the link. - * - href: The system path to link to. - * - localized_options: An array of options to pass to url(). - * - * @param $active_trail - * An array containing breadcrumb links for the current page. - * @param $item - * The menu router item of the current page. - * - * @see drupal_set_breadcrumb() - * @see menu_get_active_breadcrumb() - * @see menu_get_active_trail() - * @see menu_set_active_trail() - */ -function hook_menu_breadcrumb_alter(&$active_trail, $item) { - // Always display a link to the current page by duplicating the last link in - // the active trail. This means that menu_get_active_breadcrumb() will remove - // the last link (for the current page), but since it is added once more here, - // it will appear. - if (!drupal_is_front_page()) { - $end = end($active_trail); - if ($item['href'] == $end['href']) { - $active_trail[] = $end; - } - } -} - -/** * Alter contextual links before they are rendered. * * This hook is invoked by menu_contextual_links(). The system-determined diff --git a/core/modules/system/system.services.yml b/core/modules/system/system.services.yml index 08d67ad..cbeca48 100644 --- a/core/modules/system/system.services.yml +++ b/core/modules/system/system.services.yml @@ -10,6 +10,11 @@ services: class: Drupal\system\LegacyBreadcrumbBuilder tags: - {name: breadcrumb_builder, priority: 500} + system.breadcrumb.default: + class: Drupal\system\PathBasedBreadcrumbBuilder + arguments: ['@request', '@plugin.manager.entity', '@access_manager', '@string_translation', '@router', '@path_processor_manager', '@config.factory'] + tags: + - { name: breadcrumb_builder, priority: 0 } path_processor.files: class: Drupal\system\PathProcessor\PathProcessorFiles tags: diff --git a/core/modules/taxonomy/taxonomy.routing.yml b/core/modules/taxonomy/taxonomy.routing.yml index 0245c19..de59859 100644 --- a/core/modules/taxonomy/taxonomy.routing.yml +++ b/core/modules/taxonomy/taxonomy.routing.yml @@ -2,6 +2,7 @@ taxonomy_vocabulary_list: pattern: '/admin/structure/taxonomy' defaults: _entity_list: 'taxonomy_vocabulary' + _title: 'Taxonomy' requirements: _permission: 'administer taxonomy'