You are here

class GroupContentTypeBreadcrumbBuilder in Group 2.0.x

Same name and namespace in other branches
  1. 8 src/Breadcrumb/GroupContentTypeBreadcrumbBuilder.php \Drupal\group\Breadcrumb\GroupContentTypeBreadcrumbBuilder

Provides a custom breadcrumb builder for group content type paths.

Hierarchy

Expanded class hierarchy of GroupContentTypeBreadcrumbBuilder

1 string reference to 'GroupContentTypeBreadcrumbBuilder'
group.services.yml in ./group.services.yml
group.services.yml
1 service uses GroupContentTypeBreadcrumbBuilder
group_content_type.breadcrumb in ./group.services.yml
Drupal\group\Breadcrumb\GroupContentTypeBreadcrumbBuilder

File

src/Breadcrumb/GroupContentTypeBreadcrumbBuilder.php, line 15

Namespace

Drupal\group\Breadcrumb
View source
class GroupContentTypeBreadcrumbBuilder implements BreadcrumbBuilderInterface {
  use StringTranslationTrait;

  /**
   * @inheritdoc
   */
  public function applies(RouteMatchInterface $route_match) {

    // Only apply to paths containing a group content type.
    if ($route_match
      ->getParameter('group_content_type') instanceof GroupContentTypeInterface) {
      return TRUE;
    }
  }

  /**
   * @inheritdoc
   */
  public function build(RouteMatchInterface $route_match) {

    /** @var \Drupal\group\Entity\GroupContentTypeInterface $group_content_type */
    $group_content_type = $route_match
      ->getParameter('group_content_type');
    $group_type = $group_content_type
      ->getGroupType();
    $breadcrumb = new Breadcrumb();
    $breadcrumb
      ->addLink(Link::createFromRoute($this
      ->t('Home'), '<front>'));
    $breadcrumb
      ->addLink(Link::createFromRoute($this
      ->t('Administration'), 'system.admin'));
    $breadcrumb
      ->addLink(Link::createFromRoute($this
      ->t('Groups'), 'entity.group.collection'));
    $breadcrumb
      ->addLink(Link::createFromRoute($this
      ->t('Group types'), 'entity.group_type.collection'));
    $breadcrumb
      ->addLink(Link::createFromRoute($group_type
      ->label(), 'entity.group_type.edit_form', [
      'group_type' => $group_type
        ->id(),
    ]));
    $breadcrumb
      ->addLink(Link::createFromRoute($this
      ->t('Content'), 'entity.group_type.content_plugins', [
      'group_type' => $group_type
        ->id(),
    ]));

    // Add a link to the Configure page for any non-default tab.
    if ($route_match
      ->getRouteName() != 'entity.group_content_type.edit_form') {
      $breadcrumb
        ->addLink(Link::createFromRoute($this
        ->t('Configure'), 'entity.group_content_type.edit_form', [
        'group_content_type' => $group_content_type
          ->id(),
      ]));
    }

    // Breadcrumb needs to have the group type and group content type as
    // cacheable dependencies because any changes to them should be reflected.
    $breadcrumb
      ->addCacheableDependency($group_type);
    $breadcrumb
      ->addCacheableDependency($group_content_type);

    // This breadcrumb builder is based on a route parameter, and hence it
    // depends on the 'route' cache context.
    $breadcrumb
      ->addCacheContexts([
      'route',
    ]);
    return $breadcrumb;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GroupContentTypeBreadcrumbBuilder::applies public function @inheritdoc Overrides BreadcrumbBuilderInterface::applies
GroupContentTypeBreadcrumbBuilder::build public function @inheritdoc Overrides BreadcrumbBuilderInterface::build
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
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.