public function build(RouteMatchInterface $route_match) {
    $breadcrumb = new Breadcrumb();
    $breadcrumb->addCacheContexts(['route']);

    // Add all parent forums to breadcrumbs.
    /** @var Node $node */
    $node = $route_match->getParameter('node');
    $breadcrumb->addCacheableDependency($node);

    // Add all parent forums to breadcrumbs.
    /** @var \Drupal\Taxonomy\TermInterface $term */
    $term = !(empty($node->field_channel)) ? $node->field_channel->entity : '';

    $links = [];
    if ($term) {
      $breadcrumb->addCacheableDependency($term);

      $channels = $this->termStorage->loadAllParents($term->id());
      foreach (array_reverse($channels) as $term) {
        $term = $this->entityRepository->getTranslationFromContext($term);
        $breadcrumb->addCacheableDependency($term);
        $links[] = Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', ['taxonomy_term' => $term->id()]);
      }
    }
    if (!$links || '/' . $links[0]->getUrl()->getInternalPath() != $this->configFactory->get('system.site')->get('page.front')) {
      array_unshift($links, Link::createFromRoute($this->t('Home'), '<front>'));
    }

    return $breadcrumb->setLinks($links);
  }
public function build(RouteMatchInterface $route_match) {
    $breadcrumb = new Breadcrumb();
    $breadcrumb->addCacheContexts(['route']);

    
    
    $node = $route_match->getParameter('node');
    $breadcrumb->addCacheableDependency($node);

    
    
    $term = !(empty($node->field_channel)) ? $node->field_channel->entity : '';

    $links = [];
    if ($term) {
      $breadcrumb->addCacheableDependency($term);

      $channels = $this->termStorage->loadAllParents($term->id());
      foreach (array_reverse($channels) as $term) {
        $term = $this->entityRepository->getTranslationFromContext($term);
        $breadcrumb->addCacheableDependency($term);
        $links[] = Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', ['taxonomy_term' => $term->id()]);
      }
    }
    if (!$links || '/' . $links[0]->getUrl()->getInternalPath() != $this->configFactory->get('system.site')->get('page.front')) {
      array_unshift($links, Link::createFromRoute($this->t('Home'), '<front>'));
    }

    return $breadcrumb->setLinks($links);
  }
public function build ( RouteMatchInterface $ route_match ) { $ breadcrumb = new Breadcrumb ( ) ; $ breadcrumb -> addCacheContexts ( [ 'route' ] ) ; // Add all parent forums to breadcrumbs. /** @var Node $node */ $ node = $ route_match -> getParameter ( 'node' ) ; $ breadcrumb -> addCacheableDependency ( $ node ) ; // Add all parent forums to breadcrumbs. /** @var \Drupal\Taxonomy\TermInterface $term */ $ term = ! ( empty ( $ node -> field_channel ) ) ? $ node -> field_channel -> entity : '' ; $ links = [ ] ; if ( $ term ) { $ breadcrumb -> addCacheableDependency ( $ term ) ; $ channels = $ this -> termStorage -> loadAllParents ( $ term -> id ( ) ) ; foreach ( array_reverse ( $ channels ) as $ term ) { $ term = $ this -> entityRepository -> getTranslationFromContext ( $ term ) ; $ breadcrumb -> addCacheableDependency ( $ term ) ; $ links [ ] = Link :: createFromRoute ( $ term -> getName ( ) , 'entity.taxonomy_term.canonical' , [ 'taxonomy_term' => $ term -> id ( ) ] ) ; } } if ( ! $ links || '/' . $ links [ 0 ] -> getUrl ( ) -> getInternalPath ( ) != $ this -> configFactory -> get ( 'system.site' ) -> get ( 'page.front' ) ) { array_unshift ( $ links , Link :: createFromRoute ( $ this -> t ( 'Home' ) , '<front>' ) ) ; } return $ breadcrumb -> setLinks ( $ links ) ; }
{@inheritdoc}
{