diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index cf1fcc9be6542a5772b76389147530898fee99c1..9878d34b7675bc937e45a220d745470eb7c2be69 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -336,6 +336,9 @@ function layout_builder_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMa 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'); + 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 diff --git a/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module b/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module index 791034ddd6a86059e31f08c934691de1e4d48d12..cd6070f53ff33d4f20ef609513ff335c57b63c60 100644 --- a/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module +++ b/core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module @@ -5,10 +5,14 @@ * Provides hook implementations for Layout Builder tests. */ +use Drupal\Core\Breadcrumb\Breadcrumb; use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Link; +use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Url; /** * Implements hook_plugin_filter_TYPE__CONSUMER_alter(). @@ -106,3 +110,24 @@ function layout_builder_entity_form_display_alter(EntityFormDisplayInterface $fo ]); } } + +/** + * Implements hook_system_breadcrumb_alter(). + */ +function layout_builder_test_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInterface $route_match, array $context) { + $breadcrumb->addLink(Link::fromTextAndUrl('External link', Url::fromUri('http://www.example.com'))); +} + +/** + * Implements hook_module_implements_alter(). + */ +function layout_builder_test_module_implements_alter(&$implementations, $hook) { + if ($hook === 'system_breadcrumb_alter') { + // Move our hook_system_breadcrumb_alter() implementation to run before + // layout_builder_system_breadcrumb_alter(). + $group = $implementations['layout_builder_test']; + $implementations = [ + 'layout_builder_test' => $group, + ] + $implementations; + } +} diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php index 9a1dc75c6c15dd294050bfebc9f11fa3e01dd095..bd417da4487aed5a78c9329be648171844403997 100644 --- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php @@ -1230,6 +1230,7 @@ public function testBreadcrumb() { 'Content types' => $base_path . 'admin/structure/types', 'Bundle with section field' => $base_path . 'admin/structure/types/manage/bundle_with_section_field', 'Manage display' => $base_path . 'admin/structure/types/manage/bundle_with_section_field/display/default', + 'External link' => 'http://www.example.com', ]; $this->assertSame($expected, $breadcrumb_titles); }