You are here

class SocialCommentBreadcrumbBuilder in Open Social 8.2

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

Class to define the comment breadcrumb builder.

Hierarchy

Expanded class hierarchy of SocialCommentBreadcrumbBuilder

1 string reference to 'SocialCommentBreadcrumbBuilder'
social_comment.services.yml in modules/social_features/social_comment/social_comment.services.yml
modules/social_features/social_comment/social_comment.services.yml
1 service uses SocialCommentBreadcrumbBuilder
social_comment.breadcrumb in modules/social_features/social_comment/social_comment.services.yml
Drupal\social_comment\SocialCommentBreadcrumbBuilder

File

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

Namespace

Drupal\social_comment
View source
class SocialCommentBreadcrumbBuilder implements BreadcrumbBuilderInterface {
  use StringTranslationTrait;

  /**
   * The comment storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $storage;

  /**
   * Constructs the SocialCommentBreadcrumbBuilder.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityManagerInterface $entity_manager) {
    $this->storage = $entity_manager
      ->getStorage('comment');
  }

  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    $comments_routes = [
      'comment.reply',
      'entity.comment.edit_form',
      'entity.comment.delete_form',
    ];
    return in_array($route_match
      ->getRouteName(), $comments_routes);
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SocialCommentBreadcrumbBuilder::$storage protected property The comment storage.
SocialCommentBreadcrumbBuilder::applies public function Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface::applies
SocialCommentBreadcrumbBuilder::build public function Builds the breadcrumb. Overrides BreadcrumbBuilderInterface::build
SocialCommentBreadcrumbBuilder::__construct public function Constructs the SocialCommentBreadcrumbBuilder.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.