function LayoutBuilderHooks::systemBreadcrumbAlter
Implements hook_system_breadcrumb_alter().
File
-
core/
modules/ layout_builder/ src/ Hook/ LayoutBuilderHooks.php, line 338
Class
- LayoutBuilderHooks
- Hook implementations for layout_builder.
Namespace
Drupal\layout_builder\HookCode
public function systemBreadcrumbAlter(Breadcrumb &$breadcrumb, RouteMatchInterface $route_match, array $context) : void {
// Remove the extra 'Manage display' breadcrumb for Layout Builder defaults.
if ($route_match->getRouteObject() && $route_match->getRouteObject()
->hasOption('_layout_builder') && $route_match->getParameter('section_storage_type') === 'defaults') {
$links = array_filter($breadcrumb->getLinks(), function (Link $link) use ($route_match) {
$entity_type_id = $route_match->getParameter('entity_type_id');
if (!$link->getUrl()
->isRouted()) {
return TRUE;
}
return $link->getUrl()
->getRouteName() !== "entity.entity_view_display.{$entity_type_id}.default";
});
// Links cannot be removed from an existing breadcrumb object. Create a new
// object but carry over the cacheable metadata.
$cacheability = CacheableMetadata::createFromObject($breadcrumb);
$breadcrumb = new Breadcrumb();
$breadcrumb->setLinks($links);
$breadcrumb->addCacheableDependency($cacheability);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.