diff --git a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderInterface.php b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderInterface.php index c19100e..0237211 100644 --- a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderInterface.php +++ b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderInterface.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Breadcrumb; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\ParameterBag; /** * Defines an interface for classes that build breadcrumbs. @@ -17,13 +17,13 @@ /** * Build the breadcrumb. * - * @param \Symfony\Component\HttpFoundation\Request $request - * The HttpRequest object representing the current request. + * @param \Symfony\Component\HttpFoundation\ParameterBag $attributes + * Attributes representing the current page. * * @return array|FALSE|NULL * A render array for the breacrumbs, or * FALSE, to suppress breadcrumbs on this page, or * NULL, to let other builders decide. */ - public function build(Request $request); + public function build(ParameterBag $attributes); } diff --git a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php index f9d06a3..0f98431 100644 --- a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php +++ b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Breadcrumb; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\ParameterBag; /** * Breadcrumb manager. @@ -49,25 +49,41 @@ public function addBuilder(BreadcrumbBuilderInterface $builder, $priority) { /** * Implements Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface::build(). * - * @param \Symfony\Component\HttpFoundation\Request $request - * The HttpRequest object representing the current request. + * @param \Symfony\Component\HttpFoundation\ParameterBag $attributes + * Attributes representing the current page. * - * @return array|FALSE|NULL - * A render array for the breacrumb, or - * FALSE, if one of the builders explicitly wants no breadcrumb, or - * NULL, if no plugin found a breadcrumb. - * In the general use case, FALSE and NULL will have the same effect. + * @return array + * An array of rendered breadcrumb links, or + * an empty array(), to suppress breadcrumbs on this page. + * (This implementation will never return NULL). */ - public function build(Request $request) { - // Call the build method of all breadcrumb builders. + public function build(ParameterBag $attributes) { + // Call the build method of registered breadcrumb builders, + // until one of them returns something other than NULL. foreach ($this->getSortedBuilders() as $builder) { - $breadcrumb = $builder->build($request); - if (isset($breadcrumb)) { - // $breadcrumb may be either a render array, - // or FALSE, to suppress the breadcrumbs on this page. + $breadcrumb = $builder->build($attributes); + if (!isset($breadcrumb)) { + // The builder returned NULL, so we continue with the other builders. + continue; + } + elseif (is_array($breadcrumb)) { + // The builder returned an array of breadcrumb links. return $breadcrumb; } + elseif (FALSE === $breadcrumb) { + // A value of FALSE indicates that no breadcrumb should be displayed. + // BreadcrumbBuilderInterface dictates to return array() in this case. + return array(); + } + else { + $class = get_class($builder); + // TODO: Dedicated exception class. + throw new \Exception("Invalid breadcrumb returned by $class::build()."); + } } + + // Fall back to an empty breadcrumb. + return array(); } /** diff --git a/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php b/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php index 3ee7df1..3a131fc 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php +++ b/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php @@ -8,7 +8,7 @@ namespace Drupal\forum; use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\ParameterBag; /** * Class to define the forum breadcrumb builder. @@ -18,18 +18,18 @@ class ForumBreadcrumbBuilder implements BreadcrumbBuilderInterface { /** * Implements \Drupal\Breadcrumb\BreadcrumbBuilderInterface::build(). * - * @param \Symfony\Component\HttpFoundation\Request $request - * The HttpRequest object representing the current request. + * @param \Symfony\Component\HttpFoundation\ParameterBag $attributes + * Attributes representing the current page. * - * @return array|FALSE|NULL - * A render array for the breacrumbs, or - * FALSE, to suppress breadcrumbs on this page, or + * @return array|NULL + * An array of rendered breadcrumb links, or + * an empty array(), to suppress breadcrumbs on this page, or * NULL, to let other builders decide. */ - public function build(Request $request) { + public function build(ParameterBag $attributes) { - if ($request->attributes->has('drupal_menu_item')) { - $item = $request->attributes->get('drupal_menu_item'); + if ($attributes->has('drupal_menu_item')) { + $item = $attributes->get('drupal_menu_item'); switch ($item['path']) { case 'node/%': @@ -51,10 +51,7 @@ public function build(Request $request) { } if (!empty($breadcrumb)) { - return array( - '#theme' => 'breadcrumb', - '#breadcrumb' => $breadcrumb, - ); + return $breadcrumb; } } 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 5002b64..26991f9 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php @@ -8,7 +8,7 @@ namespace Drupal\menu_link; use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\ParameterBag; /** * Class to define the menu_link breadcrumb builder. @@ -18,27 +18,25 @@ class MenuLinkBreadcrumbBuilder implements BreadcrumbBuilderInterface { /** * Implements \Drupal\Breadcrumb\BreadcrumbBuilderInterface::build(). * - * @param \Symfony\Component\HttpFoundation\Request $request - * The HttpRequest object representing the current request. + * @param \Symfony\Component\HttpFoundation\ParameterBag $attributes + * Attributes representing the current page. * - * @return array|FALSE|NULL - * A render array for the breacrumbs, or - * FALSE, to suppress breadcrumbs on this page, or + * @return array|NULL + * An array of rendered breadcrumb links, or + * an empty array(), to suppress breadcrumbs on this page, or * NULL, to let other builders decide. */ - public function build(Request $request) { + public function build(ParameterBag $attributes) { // TODO: Rewrite the implementation. $breadcrumb = menu_get_active_breadcrumb(); if (is_array($breadcrumb)) { // $breadcrumb is expected to be an array of rendered breadcrumb links. - return array( - '#theme' => 'breadcrumb', - '#breadcrumb' => $breadcrumb, - ); - } - else { - // $breadcrumb is expected to be FALSE or NULL. return $breadcrumb; } + elseif (FALSE === $breadcrumb) { + // A value of FALSE indicates that no breadcrumb should be displayed. + // BreadcrumbBuilderInterface dictates to return array() in this case. + return array(); + } } } diff --git a/core/modules/system/lib/Drupal/system/LegacyBreadcrumbBuilder.php b/core/modules/system/lib/Drupal/system/LegacyBreadcrumbBuilder.php index d7ea9bd..c8ec0d8 100644 --- a/core/modules/system/lib/Drupal/system/LegacyBreadcrumbBuilder.php +++ b/core/modules/system/lib/Drupal/system/LegacyBreadcrumbBuilder.php @@ -8,7 +8,7 @@ namespace Drupal\system; use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\ParameterBag; /** * Class to define the legacy breadcrumb builder. @@ -22,26 +22,24 @@ class LegacyBreadcrumbBuilder implements BreadcrumbBuilderInterface { /** * Implements \Drupal\Breadcrumb\BreadcrumbBuilderInterface::build(). * - * @param \Symfony\Component\HttpFoundation\Request $request - * The HttpRequest object representing the current request. + * @param \Symfony\Component\HttpFoundation\ParameterBag $attributes + * Attributes representing the current page. * - * @return array|FALSE|NULL - * A render array for the breacrumbs, or - * FALSE, to suppress breadcrumbs on this page, or + * @return array|NULL + * An array of rendered breadcrumb links, or + * an empty array(), to suppress breadcrumbs on this page, or * NULL, to let other builders decide. */ - public function build(Request $request) { + public function build(ParameterBag $attributes) { $breadcrumb = drupal_set_breadcrumb(); if (is_array($breadcrumb)) { // $breadcrumb is expected to be an array of rendered breadcrumb links. - return array( - '#theme' => 'breadcrumb', - '#breadcrumb' => $breadcrumb, - ); - } - else { - // $breadcrumb is expected to be FALSE or NULL. return $breadcrumb; } + elseif (FALSE === $breadcrumb) { + // A value of FALSE indicates that no breadcrumb should be displayed. + // BreadcrumbBuilderInterface dictates to return array() in this case. + return array(); + } } } 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 1420199..3672886 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 @@ -24,19 +24,22 @@ class SystemBreadcrumbBlock extends BlockBase { /** - * Implements \Drupal\block\BlockBase::build(). + * Implements \Drupal\block\BlockBase::blockBuild(). * * @return array|NULL * A render array to display the breadcrumbs for the current page, or - * NULL, if no breadcrumb should be displayed. + * NULL, if no breadcrumb block should be displayed. */ - public function build() { - $builder = Drupal::service('breadcrumb'); + public function blockBuild() { + $breadcrumb_manager = Drupal::service('breadcrumb'); $request = Drupal::service('request'); - $breadcrumb = $builder->build($request); + $breadcrumb = $breadcrumb_manager->build($request->attributes); if (!empty($breadcrumb)) { - // $breadcrumb is expected to be a render array. - return $breadcrumb; + // $breadcrumb is expected to be an array of rendered breadcrumb links. + return array( + '#theme' => 'breadcrumb', + '#breadcrumb' => $breadcrumb, + ); } } }