function layout_builder_system_breadcrumb_alter in Drupal 8
Same name and namespace in other branches
- 9 core/modules/layout_builder/layout_builder.module \layout_builder_system_breadcrumb_alter()
- 10 core/modules/layout_builder/layout_builder.module \layout_builder_system_breadcrumb_alter()
Implements hook_system_breadcrumb_alter().
File
- core/
modules/ layout_builder/ layout_builder.module, line 334 - Provides hook implementations for Layout Builder.
Code
function layout_builder_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInterface $route_match, array $context) {
// Remove the extra 'Manage display' breadcrumb for Layout Builder defaults.
if ($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');
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);
}
}