class CatalogBreadcrumbBuilder in Ubercart 8.4
Provides a custom breadcrumb builder for catalog node and listing pages.
Hierarchy
- class \Drupal\uc_catalog\CatalogBreadcrumbBuilder implements BreadcrumbBuilderInterface uses StringTranslationTrait
Expanded class hierarchy of CatalogBreadcrumbBuilder
1 string reference to 'CatalogBreadcrumbBuilder'
- uc_catalog.services.yml in uc_catalog/
uc_catalog.services.yml - uc_catalog/uc_catalog.services.yml
1 service uses CatalogBreadcrumbBuilder
File
- uc_catalog/
src/ CatalogBreadcrumbBuilder.php, line 15
Namespace
Drupal\uc_catalogView source
class CatalogBreadcrumbBuilder implements BreadcrumbBuilderInterface {
use StringTranslationTrait;
/**
* The taxonomy storage.
*
* @var \Drupal\Taxonomy\TermStorageInterface
*/
protected $termStorage;
/**
* Constructs a new CatalogBreadcrumbBuilder.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->termStorage = $entity_type_manager
->getStorage('taxonomy_term');
}
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
$route_name = $route_match
->getRouteName();
return $route_name == 'entity.node.canonical' && $route_match
->getParameter('node') && !empty($route_match
->getParameter('node')->taxonomy_catalog->target_id) || substr($route_name, 0, 16) == 'view.uc_catalog.' && $route_match
->getParameter('arg_0');
}
/**
* {@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('Catalog'), 'view.uc_catalog.page_1'));
if ($route_match
->getRouteName() == 'entity.node.canonical') {
// Extract term ID for node view.
$tid = $route_match
->getParameter('node')->taxonomy_catalog->target_id;
$skip_last = FALSE;
}
else {
// Get term ID argument for catalog view, and skip the last term.
$tid = $route_match
->getParameter('arg_0');
$skip_last = TRUE;
}
if ($parents = $this->termStorage
->loadAllParents($tid)) {
if ($skip_last) {
array_shift($parents);
}
$parents = array_reverse($parents);
foreach ($parents as $parent) {
$breadcrumb
->addCacheableDependency($parent);
$breadcrumb
->addLink(Link::createFromRoute($parent
->label(), 'view.uc_catalog.page_1', [
'arg_0' => $parent
->id(),
]));
}
}
return $breadcrumb;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CatalogBreadcrumbBuilder:: |
protected | property | The taxonomy storage. | |
CatalogBreadcrumbBuilder:: |
public | function |
Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
CatalogBreadcrumbBuilder:: |
public | function |
Builds the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
CatalogBreadcrumbBuilder:: |
public | function | Constructs a new CatalogBreadcrumbBuilder. | |
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. |