diff --git a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php index 5b3cb65..d6d2d0f 100644 --- a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php +++ b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php @@ -18,21 +18,12 @@ class BreadcrumbManager implements BreadcrumbBuilderInterface { /** - * Holds the array of breadcrumb builders to cycle through. - * - * @var array - * An array whose keys are priorities and whose values are arrays of - * breadcrumb builder objects. - */ - protected $builders = array(); - - /** - * Holds the array of breadcrumb builders sorted by priority. + * Holds the array of breadcrumb builders, sorted by priority. * * @var array * An array of breadcrumb builders sorted by priorities. */ - protected $sortedBuilders; + protected $builders = array(); /* * Add another breadcrumb builder. @@ -44,7 +35,9 @@ class BreadcrumbManager implements BreadcrumbBuilderInterface { */ public function addBuilder(BreadcrumbBuilderInterface $builder, $priority) { $this->builders[$priority][] = $builder; - unset($this->sortedBuilders); + // The internal $this->builders array always needs to be correctly sorted. + // Builders with high priority are first in the array. + krsort($this->builders); } /** @@ -54,30 +47,14 @@ public function addBuilder(BreadcrumbBuilderInterface $builder, $priority) { * The HttpRequest object representing the current request. */ public function build(Request $request) { - foreach ($this->getSortedBuilders() as $builder) { - $breadcrumb = $builder->build($request); - if (isset($breadcrumb) && is_array($breadcrumb)) { - return $breadcrumb; - } - } - } - - /** - * Returns the sorted array of breadcrumb builders. - * - * @return array - * An array of breadcrumb builder objects. - */ - protected function getSortedBuilders() { - if (!isset($this->sortedBuilders)) { - // Sort the builders according to priority. - krsort($this->builders); - // Merge the nested $this->builders array into $this->sortedBuilders. - $this->sortedBuilders = array(); - foreach ($this->builders as $builders) { - $this->sortedBuilders = array_merge($this->sortedBuilders, $builders); + // Call the build method of all breadcrumb builders. + foreach ($this->builders as $priority => $builders) { + foreach ($builders as $builder) { + $breadcrumb = $builder->build($request); + if (isset($breadcrumb) && is_array($breadcrumb)) { + return $breadcrumb; + } } } - return $this->sortedBuilders; } } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php index c7a1b71..992b6da 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php @@ -22,48 +22,8 @@ class MenuLinkBreadcrumbBuilder implements BreadcrumbBuilderInterface { * The HttpRequest object representing the current request. */ public function build(Request $request) { - $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 ($item['href'] == $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']); - } - } + // TODO: Move the implementation out of menu.inc, into this method. + $breadcrumb = menu_get_active_breadcrumb(); return $breadcrumb; } } diff --git a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemBreadcrumbBlock.php b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemBreadcrumbBlock.php index c2c6e39..813005b 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemBreadcrumbBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/block/block/SystemBreadcrumbBlock.php @@ -7,7 +7,6 @@ namespace Drupal\system\Plugin\block\block; -use Drupal; use Drupal\block\BlockBase; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; @@ -27,9 +26,10 @@ class SystemBreadcrumbBlock extends BlockBase { * Implements \Drupal\block\BlockBase::build(). */ public function build() { - $request = Drupal::service('request'); - $breadcrumb = Drupal::service('breadcrumb')->build($request); - if (!empty($breadcrumb) && is_array($breadcrumb)) { + $builder = \Drupal::service('breadcrumb'); + $request = \Drupal::service('request'); + $breadcrumb = $builder->build($request); + if (isset($breadcrumb) && is_array($breadcrumb)) { return array( '#theme' => 'breadcrumb', '#breadcrumb' => $breadcrumb,