From 4676911fd9c3be8aacc95929a40aebca0a051e6b Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Thu, 25 Mar 2021 20:06:05 +0000 Subject: [PATCH] Issue #3090941 by raman.b, breakfull, jmdeleon, amd.miri, tim.plunkett, rwohleb: Layout builder assumes all breadcrumb links are routable --- .../layout_builder/layout_builder.module | 3 +++ .../layout_builder_test.module | 25 +++++++++++++++++++ .../src/Functional/LayoutBuilderTest.php | 1 + 3 files changed, 29 insertions(+) diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index cf1fcc9be654..9878d34b7675 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 791034ddd6a8..cd6070f53ff3 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 9a1dc75c6c15..bd417da4487a 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); } -- GitLab