Commit 8b8ad2ed authored by catch's avatar catch
Browse files

Issue #3090941 by raman.b, breakfull, jmdeleon, amd.miri, tim.plunkett,...

Issue #3090941 by raman.b, breakfull, jmdeleon, amd.miri, tim.plunkett, rwohleb: Layout builder assumes all breadcrumb links are routable

(cherry picked from commit 4676911f)
parent 7408756e
...@@ -336,6 +336,9 @@ function layout_builder_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMa ...@@ -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') { 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) { $links = array_filter($breadcrumb->getLinks(), function (Link $link) use ($route_match) {
$entity_type_id = $route_match->getParameter('entity_type_id'); $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"; return $link->getUrl()->getRouteName() !== "entity.entity_view_display.$entity_type_id.default";
}); });
// Links cannot be removed from an existing breadcrumb object. Create a new // Links cannot be removed from an existing breadcrumb object. Create a new
......
...@@ -5,10 +5,14 @@ ...@@ -5,10 +5,14 @@
* Provides hook implementations for Layout Builder tests. * Provides hook implementations for Layout Builder tests.
*/ */
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Entity\Display\EntityFormDisplayInterface; use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface; 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(). * Implements hook_plugin_filter_TYPE__CONSUMER_alter().
...@@ -106,3 +110,24 @@ function layout_builder_entity_form_display_alter(EntityFormDisplayInterface $fo ...@@ -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;
}
}
...@@ -1199,6 +1199,7 @@ public function testBreadcrumb() { ...@@ -1199,6 +1199,7 @@ public function testBreadcrumb() {
'Content types' => $base_path . 'admin/structure/types', 'Content types' => $base_path . 'admin/structure/types',
'Bundle with section field' => $base_path . 'admin/structure/types/manage/bundle_with_section_field', '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', '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); $this->assertSame($expected, $breadcrumb_titles);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment