diff --git a/core/includes/common.inc b/core/includes/common.inc index 4f72021..2c2bb87 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -283,6 +283,11 @@ function drupal_get_profile() { * @param $breadcrumb * Array of links, starting with "home" and proceeding up to but not including * the current page. + * + * @deprecated This will be removed in 8.0. Instead, register a new breadcrumb + * builder service. + * + * @see Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface */ function drupal_set_breadcrumb($breadcrumb = NULL) { $stored_breadcrumb = &drupal_static(__FUNCTION__); @@ -295,6 +300,11 @@ function drupal_set_breadcrumb($breadcrumb = NULL) { /** * Gets the breadcrumb trail for the current page. + * + * @deprecated This will be removed in 8.0. Instead, register a new breadcrumb + * builder service. + * + * @see Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface */ function drupal_get_breadcrumb() { $breadcrumb = drupal_set_breadcrumb(); diff --git a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderInterface.php b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderInterface.php index c0d3879..c3d4c36 100644 --- a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderInterface.php +++ b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderInterface.php @@ -17,7 +17,7 @@ /** * Build the breadcrumb. * - * @param \Symfony\Component\HttpFoundation\ParameterBag $attributes + * @param array $attributes * Attributes representing the current page. * * @return array|FALSE|NULL @@ -25,6 +25,6 @@ * FALSE, to suppress breadcrumbs on this page, or * NULL, to let other builders decide. */ - public function build(ParameterBag $attributes); + public function build(array $attributes); } diff --git a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php index 330b84d..6d015e8 100644 --- a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php +++ b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php @@ -47,17 +47,9 @@ public function addBuilder(BreadcrumbBuilderInterface $builder, $priority) { } /** - * Implements Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface::build(). - * - * @param \Symfony\Component\HttpFoundation\ParameterBag $attributes - * Attributes representing the current page. - * - * @return array - * An array of rendered breadcrumb links, or - * an empty array(), to suppress breadcrumbs on this page. - * (This implementation will never return NULL). + * {@inheritdoc} */ - public function build(ParameterBag $attributes) { + public function build(array $attributes) { // Call the build method of registered breadcrumb builders, // until one of them returns something other than NULL. foreach ($this->getSortedBuilders() as $builder) { diff --git a/core/modules/forum/forum.services.yml b/core/modules/forum/forum.services.yml index ff9f695..19033e8 100644 --- a/core/modules/forum/forum.services.yml +++ b/core/modules/forum/forum.services.yml @@ -1,5 +1,6 @@ services: forum.breadcrumb: class: Drupal\forum\ForumBreadcrumbBuilder + arguments: ['@plugin.manager.entity', '@config.factory'] tags: - { name: breadcrumb_builder, priority: 1001 } diff --git a/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php b/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php index f6c451c..fedb5f1 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php +++ b/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php @@ -7,21 +7,51 @@ namespace Drupal\forum; -use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; use Symfony\Component\HttpFoundation\ParameterBag; +use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; +use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Entity\EntityManager; + /** * Class to define the forum breadcrumb builder. */ class ForumBreadcrumbBuilder implements BreadcrumbBuilderInterface { /** + * Configuration object for this builder. + * + * @var ;Drupal\Core\Config\Config + */ + protected $config; + + /** + * Stores the Entity manager. + * + * @var \Drupal\Core\Entity\EntityManager + */ + protected $entityManager; + + /** + * Constructs a new ForumBreadcrumbBuilder. + * + * @param \Drupal\Core\Config\ConfigFactory $configFactory + * The configuration factory. + */ + public function __construct(EntityManager $entity_manager, ConfigFactory $configFactory) { + $this->entityManager = $entity_manager; + $this->config = $configFactory->get('forum.settings'); + } + + /** * {@inheritdoc} */ - public function build(ParameterBag $attributes) { + public function build(array $attributes) { - if ($attributes->has('drupal_menu_item')) { - $item = $attributes->get('drupal_menu_item'); + // @todo This only works for legacy routes. Once node/% and forum/% are + // converted to the new router this code will need to be updated. + if (isset($attributes['drupal_menu_item'])) { + $item = $attributes['drupal_menu_item']; switch ($item['path']) { case 'node/%': @@ -51,8 +81,8 @@ public function build(ParameterBag $attributes) { * Builds the breadcrumb for a forum post page. */ protected function forumPostBreadcrumb($node) { - $config = config('forum.settings'); - $vocabulary = entity_load('taxonomy_vocabulary', $config->get('vocabulary')); + $vocabularies = $this->entityManager->getStorageController('taxonomy_vocabulary')->load(array($this->config->get('vocabulary'))); + $vocabulary = current($vocabularies); $breadcrumb[] = l(t('Home'), NULL); $breadcrumb[] = l($vocabulary->name, 'forum'); @@ -69,8 +99,8 @@ protected function forumPostBreadcrumb($node) { * Builds the breadcrumb for a forum term page. */ protected function forumTermBreadcrumb($term) { - $config = config('forum.settings'); - $vocabulary = entity_load('taxonomy_vocabulary', $config->get('vocabulary')); + $vocabularies = $this->entityManager->getStorageController('taxonomy_vocabulary')->load(array($this->config->get('vocabulary'))); + $vocabulary = current($vocabularies); $breadcrumb[] = l(t('Home'), NULL); if ($term->tid) { 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 c0ea0e4..5814db5 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkBreadcrumbBuilder.php @@ -18,7 +18,7 @@ class MenuLinkBreadcrumbBuilder implements BreadcrumbBuilderInterface { /** * {@inheritdoc} */ - public function build(ParameterBag $attributes) { + public function build(array $attributes) { // @todo Rewrite the implementation. $breadcrumb = menu_get_active_breadcrumb(); if (is_array($breadcrumb)) { diff --git a/core/modules/system/lib/Drupal/system/LegacyBreadcrumbBuilder.php b/core/modules/system/lib/Drupal/system/LegacyBreadcrumbBuilder.php index 4224119..7b6fc7c 100644 --- a/core/modules/system/lib/Drupal/system/LegacyBreadcrumbBuilder.php +++ b/core/modules/system/lib/Drupal/system/LegacyBreadcrumbBuilder.php @@ -13,6 +13,11 @@ /** * Class to define the legacy breadcrumb builder. * + * @deprecated This will be removed in 8.0. Instead, register a new breadcrumb + * builder service. + * + * @see Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface + * * This breadcrumb builder implements legacy support for the * drupal_set_breadcrumb() mechanic. * Remove this once drupal_set_breadcrumb() has been eliminated. @@ -22,7 +27,7 @@ class LegacyBreadcrumbBuilder implements BreadcrumbBuilderInterface { /** * {@inheritdoc} */ - public function build(ParameterBag $attributes) { + public function build(array $attributes) { $breadcrumb = drupal_set_breadcrumb(); if (is_array($breadcrumb)) { // $breadcrumb is expected to be an array of rendered breadcrumb links. diff --git a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBreadcrumbBlock.php b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBreadcrumbBlock.php index d99698f..b678eb6 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBreadcrumbBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemBreadcrumbBlock.php @@ -28,7 +28,7 @@ class SystemBreadcrumbBlock extends BlockBase { protected function blockBuild() { $breadcrumb_manager = \Drupal::service('breadcrumb'); $request = \Drupal::service('request'); - $breadcrumb = $breadcrumb_manager->build($request->attributes); + $breadcrumb = $breadcrumb_manager->build($request->attributes->all()); if (!empty($breadcrumb)) { // $breadcrumb is expected to be an array of rendered breadcrumb links. return array(