Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CommentBreadcrumbBuilder.php

function CommentBreadcrumbBuilder::build

Overrides BreadcrumbBuilderInterface::build

File

core/modules/comment/src/CommentBreadcrumbBuilder.php, line 49

Class

CommentBreadcrumbBuilder
Class to define the comment breadcrumb builder.

Namespace

Drupal\comment

Code

public function build(RouteMatchInterface $route_match) {
    $breadcrumb = new Breadcrumb();
    // @todo Remove in Drupal 12.0.0, will be added from ::applies(). See
    //   https://www.drupal.org/project/drupal/issues/3459277
    $breadcrumb->addCacheContexts([
        'route',
    ]);
    $breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
    $entity = $route_match->getParameter('entity');
    $breadcrumb->addLink(new Link($entity->label(), $entity->toUrl()));
    $breadcrumb->addCacheableDependency($entity);
    if (($pid = $route_match->getParameter('pid')) && ($comment = $this->entityTypeManager
        ->getStorage('comment')
        ->load($pid))) {
        
        /** @var \Drupal\comment\CommentInterface $comment */
        $breadcrumb->addCacheableDependency($comment);
        // Display link to parent comment.
        // @todo Clean-up permalink in https://www.drupal.org/node/2198041
        $breadcrumb->addLink(new Link($comment->getSubject(), $comment->toUrl()));
    }
    return $breadcrumb;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal