diff --git a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderBase.php b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderBase.php new file mode 100644 index 0000000..63fe199 --- /dev/null +++ b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderBase.php @@ -0,0 +1,89 @@ +linkGenerator()->generate($text, $route_name, $parameters, $options); + } + + /** + * Returns the link generator. + * + * @return \Drupal\Core\Utility\LinkGeneratorInterface + * The link generator + */ + protected function linkGenerator() { + if (!isset($this->linkGenerator)) { + $this->linkGenerator = $this->container()->get('link_generator'); + } + return $this->linkGenerator; + } + + /** + * Translates a string to the current language or to a given language. + * + * See the t() documentation for details. + */ + protected function t($string, array $args = array(), array $options = array()) { + return $this->translationManager()->translate($string, $args, $options); + } + + /** + * Returns the translation manager. + * + * @return \Drupal\Core\StringTranslation\TranslationInterface + * The translation manager. + */ + protected function translationManager() { + if (!$this->translationManager) { + $this->translationManager = $this->container()->get('string_translation'); + } + return $this->translationManager; + } + +} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermBreadcrumbBuilder.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermBreadcrumbBuilder.php new file mode 100644 index 0000000..9aacdcb --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermBreadcrumbBuilder.php @@ -0,0 +1,37 @@ +id())) { + $term = array_shift($parents); + $breadcrumb[] = $this->l($term->label(), 'taxonomy.term_page', array('taxonomy_term' => $term->id())); + } + $breadcrumb[] = $this->l($this->t('Home'), ''); + $breadcrumb = array_reverse($breadcrumb); + + return $breadcrumb; + } + } + +} diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc index 956bc71..ed40174 100644 --- a/core/modules/taxonomy/taxonomy.pages.inc +++ b/core/modules/taxonomy/taxonomy.pages.inc @@ -19,17 +19,6 @@ function taxonomy_term_page(Term $term) { // Assign the term name as the page title. drupal_set_title($term->label()); - // @todo This overrides any other possible breadcrumb and is a pure hard-coded - // presumption. Make this behavior configurable per vocabulary or term. - $breadcrumb = array(); - $current = $term; - while ($parents = taxonomy_term_load_parents($current->id())) { - $current = array_shift($parents); - $breadcrumb[] = l($current->label(), 'taxonomy/term/' . $current->id()); - } - $breadcrumb[] = l(t('Home'), NULL); - $breadcrumb = array_reverse($breadcrumb); - drupal_set_breadcrumb($breadcrumb); drupal_add_feed('taxonomy/term/' . $term->id() . '/feed', 'RSS - ' . $term->label()); foreach ($term->uriRelationships() as $rel) { diff --git a/core/modules/taxonomy/taxonomy.services.yml b/core/modules/taxonomy/taxonomy.services.yml new file mode 100644 index 0000000..686f6ea --- /dev/null +++ b/core/modules/taxonomy/taxonomy.services.yml @@ -0,0 +1,5 @@ +services: + taxonomy_term.breadcrumb: + class: Drupal\taxonomy\TermBreadcrumbBuilder + tags: + - { name: breadcrumb_builder, priority: 1002 }