function layout_builder_system_breadcrumb_alter

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/layout_builder.module \layout_builder_system_breadcrumb_alter()
  2. 8.9.x core/modules/layout_builder/layout_builder.module \layout_builder_system_breadcrumb_alter()
  3. 10 core/modules/layout_builder/layout_builder.module \layout_builder_system_breadcrumb_alter()

Implements hook_system_breadcrumb_alter().

1 call to layout_builder_system_breadcrumb_alter()
LayoutBuilderBreadcrumbAlterTest::testBreadcrumbAlterNullRouteMatch in core/modules/layout_builder/tests/src/Kernel/LayoutBuilderBreadcrumbAlterTest.php
Check that there are no errors when alter called with null route match.

File

core/modules/layout_builder/layout_builder.module, line 335

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() && $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.