class FarmBreadcrumbBuilder in farmOS 2.x
Build farmOS breadcrumbs.
Hierarchy
- class \Drupal\system\PathBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface uses StringTranslationTrait
- class \Drupal\farm_ui_breadcrumb\Breadcrumb\FarmBreadcrumbBuilder uses StringTranslationTrait
Expanded class hierarchy of FarmBreadcrumbBuilder
1 string reference to 'FarmBreadcrumbBuilder'
- farm_ui_breadcrumb.services.yml in modules/
core/ ui/ breadcrumb/ farm_ui_breadcrumb.services.yml - modules/core/ui/breadcrumb/farm_ui_breadcrumb.services.yml
1 service uses FarmBreadcrumbBuilder
- farm_ui_breadcrumb.breadcrumb in modules/
core/ ui/ breadcrumb/ farm_ui_breadcrumb.services.yml - Drupal\farm_ui_breadcrumb\Breadcrumb\FarmBreadcrumbBuilder
File
- modules/
core/ ui/ breadcrumb/ src/ Breadcrumb/ FarmBreadcrumbBuilder.php, line 13
Namespace
Drupal\farm_ui_breadcrumb\BreadcrumbView source
class FarmBreadcrumbBuilder extends PathBasedBreadcrumbBuilder {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match) {
$breadcrumb = parent::build($route_match);
// Get parameters.
$parameters = $route_match
->getParameters();
// Add links based on the route.
switch ($route_match
->getRouteName()) {
// Asset pages.
case 'entity.asset.canonical':
/** @var \Drupal\asset\Entity\AssetInterface $asset */
$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;
// Log pages.
case 'entity.log.canonical':
/** @var \Drupal\log\Entity\LogInterface $log */
$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;
// Plan pages.
case 'entity.plan.canonical':
/** @var \Drupal\plan\Entity\PlanInterface $plan */
$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;
}
// 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 |
---|---|---|---|---|
FarmBreadcrumbBuilder:: |
public | function |
Builds the breadcrumb. Overrides PathBasedBreadcrumbBuilder:: |
|
PathBasedBreadcrumbBuilder:: |
protected | property | The menu link access service. | |
PathBasedBreadcrumbBuilder:: |
protected | property | Site config object. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The router request context. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The current path service. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The current user object. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The patch matcher service. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The inbound path processor. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The dynamic router service. | |
PathBasedBreadcrumbBuilder:: |
protected | property | The title resolver. | |
PathBasedBreadcrumbBuilder:: |
public | function |
Whether this breadcrumb builder should be used to build the breadcrumb. Overrides BreadcrumbBuilderInterface:: |
|
PathBasedBreadcrumbBuilder:: |
protected | function | Matches a path in the router. | |
PathBasedBreadcrumbBuilder:: |
public | function | Constructs the PathBasedBreadcrumbBuilder. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. |