class GroupContentTypeBreadcrumbBuilder in Group 8
Same name and namespace in other branches
- 2.0.x src/Breadcrumb/GroupContentTypeBreadcrumbBuilder.php \Drupal\group\Breadcrumb\GroupContentTypeBreadcrumbBuilder
Provides a custom breadcrumb builder for group content type paths.
Hierarchy
- class \Drupal\group\Breadcrumb\GroupContentTypeBreadcrumbBuilder implements BreadcrumbBuilderInterface uses StringTranslationTrait
Expanded class hierarchy of GroupContentTypeBreadcrumbBuilder
1 string reference to 'GroupContentTypeBreadcrumbBuilder'
1 service uses GroupContentTypeBreadcrumbBuilder
File
- src/
Breadcrumb/ GroupContentTypeBreadcrumbBuilder.php, line 15
Namespace
Drupal\group\BreadcrumbView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GroupContentTypeBreadcrumbBuilder:: |
public | function |
@inheritdoc Overrides BreadcrumbBuilderInterface:: |
|
GroupContentTypeBreadcrumbBuilder:: |
public | function |
@inheritdoc Overrides BreadcrumbBuilderInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |