diff --git a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php index f5af77e..5396e9e 100644 --- a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php +++ b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php @@ -16,19 +16,18 @@ class BreadcrumbManager implements BreadcrumbBuilderInterface { /** - * Holds the array of breadcrumb builders, sorted by priority. + * Holds arrays of breadcrumb builders, keyed by priority. * * @var array - * An array of breadcrumb builders sorted by priorities. */ protected $builders = array(); /** * Holds the array of breadcrumb builders sorted by priority. * + * Set to NULL if the array needs to be re-calculated. + * * @var array|NULL - * An array of breadcrumb builders sorted by priorities, or - * NULL, if the array needs to be re-calculated. */ protected $sortedBuilders; @@ -42,6 +41,8 @@ class BreadcrumbManager implements BreadcrumbBuilderInterface { */ public function addBuilder(BreadcrumbBuilderInterface $builder, $priority) { $this->builders[$priority][] = $builder; + // Force the builders to be re-sorted. + $this->sortedBuilders = NULL; } /** @@ -49,7 +50,7 @@ public function addBuilder(BreadcrumbBuilderInterface $builder, $priority) { */ public function build(array $attributes) { // Call the build method of registered breadcrumb builders, - // until one of them returns array. + // until one of them returns an array. foreach ($this->getSortedBuilders() as $builder) { $breadcrumb = $builder->build($attributes); if (!isset($breadcrumb)) { @@ -79,10 +80,10 @@ 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. + // Merge nested builders from $this->builders into $this->sortedBuilders. $this->sortedBuilders = array(); - foreach ($this->builders as $builder) { - $this->sortedBuilders = array_merge($this->sortedBuilders, $builder); + foreach ($this->builders as $builders) { + $this->sortedBuilders = array_merge($this->sortedBuilders, $builders); } } return $this->sortedBuilders;