diff --git a/core/modules/book/book.services.yml b/core/modules/book/book.services.yml index 3cdcda5..f7ff964 100644 --- a/core/modules/book/book.services.yml +++ b/core/modules/book/book.services.yml @@ -1,7 +1,7 @@ services: book.breadcrumb: class: Drupal\book\BookBreadcrumbBuilder - arguments: ['@entity.manager', '@string_translation', '@link_generator'] + arguments: ['@entity.manager', '@string_translation', '@link_generator', '@access_manager'] tags: - { name: breadcrumb_builder, priority: 701 } book.manager: diff --git a/core/modules/book/lib/Drupal/book/BookBreadcrumbBuilder.php b/core/modules/book/lib/Drupal/book/BookBreadcrumbBuilder.php index 61ec6a4..2fef927 100644 --- a/core/modules/book/lib/Drupal/book/BookBreadcrumbBuilder.php +++ b/core/modules/book/lib/Drupal/book/BookBreadcrumbBuilder.php @@ -7,10 +7,12 @@ namespace Drupal\book; +use Drupal\Core\Access\AccessManager; use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; use Drupal\Core\Entity\EntityManager; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Utility\LinkGeneratorInterface; +use Drupal\node\NodeInterface; /** * Provides a breadcrumb builder for nodes in a book. @@ -39,6 +41,13 @@ class BookBreadcrumbBuilder implements BreadcrumbBuilderInterface { protected $linkGenerator; /** + * The access manager. + * + * @var \Drupal\Core\Access\AccessManager + */ + protected $accessManager; + + /** * Constructs the BookBreadcrumbBuilder. * * @param \Drupal\Core\Entity\EntityManager $entity_manager @@ -47,23 +56,24 @@ class BookBreadcrumbBuilder implements BreadcrumbBuilderInterface { * The translation manager service. * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator * The link generator. + * @param \Drupal\Core\Access\AccessManager $access_manager + * The access manager. */ - public function __construct(EntityManager $entity_manager, TranslationInterface $translation, LinkGeneratorInterface $link_generator) { + public function __construct(EntityManager $entity_manager, TranslationInterface $translation, LinkGeneratorInterface $link_generator, AccessManager $access_manager) { $this->menuLinkStorage = $entity_manager->getStorageController('menu_link'); $this->translation = $translation; $this->linkGenerator = $link_generator; + $this->accessManager = $access_manager; } /** * {@inheritdoc} */ public function build(array $attributes) { - // @todo - like \Drupal\forum\ForumBreadcrumbBuilder this depends on the - // legacy non-route node view, see https://drupal.org/node/1987778. - if (!empty($attributes['_drupal_menu_item']) && !empty($attributes['_drupal_menu_item']['map'][1]->book)) { + if (!empty($attributes['node']) && $attributes['node'] instanceof NodeInterface && !empty($attributes['node']->book)) { $mlids = array(); $links = array($this->linkGenerator->generate($this->t('Home'), '')); - $book = $attributes['_drupal_menu_item']['map'][1]->book; + $book = $attributes['node']->book; $depth = 1; // We skip the current node. while (!empty($book['p' . ($depth + 1)])) { @@ -75,13 +85,8 @@ public function build(array $attributes) { $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 the node view route is converted, see - // https://drupal.org/node/1987778. - if ($item = menu_get_item($menu_link->link_path)) { - if ($item['access']) { - $links[] = l($menu_link->label(), $menu_link->link_path, $menu_link->options); - } + if ($this->accessManager->checkNamedRoute($menu_link->route_name, $menu_link->route_parameters)) { + $links[] = $this->linkGenerator->generate($menu_link->label(), $menu_link->route_name, $menu_link->route_parameters, $menu_link->options); } } $depth++; 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 ae251ea..c4a1299 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php @@ -189,21 +189,6 @@ function testBreadCrumbs() { 'plid' => 0, )), )); - $nid2 = $node2->id(); - - $trail = $home; - $tree = array( - "node/$nid2" => $node2->menu['link_title'], - ); - $this->assertBreadcrumb("node/$nid2", $trail, $node2->getTitle(), $tree); - $trail += array( - "node/$nid2" => $node2->menu['link_title'], - ); - $this->assertBreadcrumb("node/$nid2/edit", $trail); - - // Verify that node listing page still contains "Home" only. - $trail = array(); - $this->assertBreadcrumb('node', $trail); if ($menu == 'tools') { $parent = $node2;