FarmBreadcrumbBuilder.php in farmOS 2.x
File
modules/core/ui/breadcrumb/src/Breadcrumb/FarmBreadcrumbBuilder.php
View source
<?php
namespace Drupal\farm_ui_breadcrumb\Breadcrumb;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Link;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\system\PathBasedBreadcrumbBuilder;
class FarmBreadcrumbBuilder extends PathBasedBreadcrumbBuilder {
use StringTranslationTrait;
public function build(RouteMatchInterface $route_match) {
$breadcrumb = parent::build($route_match);
$parameters = $route_match
->getParameters();
switch ($route_match
->getRouteName()) {
case 'entity.asset.canonical':
$asset = $parameters
->get('asset');
$breadcrumb
->addCacheableDependency($asset);
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Records'), '<front>'));
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Assets'), 'view.farm_asset.page'));
$breadcrumb
->addLink(Link::createFromRoute($asset
->getBundleLabel(), 'view.farm_asset.page_type', [
'arg_0' => $asset
->bundle(),
]));
break;
case 'entity.log.canonical':
$log = $parameters
->get('log');
$breadcrumb
->addCacheableDependency($log);
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Records'), '<front>'));
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Logs'), 'view.farm_log.page'));
$breadcrumb
->addLink(Link::createFromRoute($log
->getBundleLabel(), 'view.farm_log.page_type', [
'arg_0' => $log
->bundle(),
]));
break;
case 'entity.plan.canonical':
$plan = $parameters
->get('plan');
$breadcrumb
->addCacheableDependency($plan);
$breadcrumb
->addLink(Link::createFromRoute($this
->t('Plans'), 'view.farm_plan.page'));
$breadcrumb
->addLink(Link::createFromRoute($plan
->getBundleLabel(), 'view.farm_plan.page_type', [
'arg_0' => $plan
->bundle(),
]));
break;
}
$breadcrumb
->addCacheContexts([
'route',
]);
return $breadcrumb;
}
}