You are here

public function SocialCommentBreadcrumbBuilder::build in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder::build()
  2. 8.2 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder::build()
  3. 8.3 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder::build()
  4. 8.4 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder::build()
  5. 8.5 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder::build()
  6. 8.6 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder::build()
  7. 8.7 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder::build()
  8. 8.8 modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder::build()
  9. 10.3.x modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder::build()
  10. 10.0.x modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder::build()
  11. 10.1.x modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder::build()
  12. 10.2.x modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php \Drupal\social_comment\SocialCommentBreadcrumbBuilder::build()

Builds the breadcrumb.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.

Return value

\Drupal\Core\Breadcrumb\Breadcrumb A breadcrumb.

Overrides BreadcrumbBuilderInterface::build

File

modules/social_features/social_comment/src/SocialCommentBreadcrumbBuilder.php, line 51

Class

SocialCommentBreadcrumbBuilder
Class to define the comment breadcrumb builder.

Namespace

Drupal\social_comment

Code

public function build(RouteMatchInterface $route_match) {
  $breadcrumb = new Breadcrumb();
  $breadcrumb
    ->addCacheContexts([
    'route',
  ]);
  $breadcrumb
    ->addLink(Link::createFromRoute($this
    ->t('Home'), '<front>'));
  $breadcrumb
    ->addLink(Link::createFromRoute($this
    ->t('Home'), '<front>'));
  switch ($route_match
    ->getRouteName()) {
    case 'comment.reply':
      $page_title = $this
        ->t('Reply to Comment');
      $pid = $route_match
        ->getParameter('pid');
      $comment = $this->storage
        ->load($pid);
      break;
    case 'entity.comment.edit_form':
      $page_title = $this
        ->t('Edit Comment');
      $comment = $route_match
        ->getParameter('comment');
      break;
    case 'entity.comment.delete_form':
      $page_title = $this
        ->t('Delete Comment');
      $comment = $route_match
        ->getParameter('comment');
      break;
    default:
      $page_title = $this
        ->t('Comment');
  }

  // Add Entity path to Breadcrumb for Reply.
  if ($route_match
    ->getParameter('entity')) {
    $entity = $route_match
      ->getParameter('entity');
    $breadcrumb
      ->addLink(new Link($entity
      ->label(), $entity
      ->urlInfo()));
    $breadcrumb
      ->addCacheableDependency($entity);
  }

  // Add Caching.
  if ($comment) {
    $breadcrumb
      ->addCacheableDependency($comment);
  }

  // Display link to current page.
  $breadcrumb
    ->addLink(new Link($page_title, Url::fromRoute('<current>')));
  return $breadcrumb;
}