Skip to content

Commit 0498719

Browse files
authored
fix/breadcrumb hook improvement (#945)
1 parent ec3996c commit 0498719

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

apps/drupal-default/particle_theme/includes/navigation.theme.inc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,31 @@
44
* @file
55
* Functions to support theming menu navigation in the Particle theme.
66
*/
7+
8+
use Drupal\search\SearchPageInterface;
9+
10+
/**
11+
* Implements hook_preprocess_breadcrumb().
12+
*/
13+
function particle_preprocess_breadcrumb(&$variables) {
14+
// Taken from Umami theme
15+
// We are creating a variable for the Current Page Title, to allow us to print
16+
// it after the breadcrumbs loop has run.
17+
$route_match = Drupal::routeMatch();
18+
// Search page titles aren't resolved using the title_resolver service - it
19+
// will always return 'Search' instead of 'Search for [term]', which would
20+
// give us a breadcrumb of Home >> Search >> Search.
21+
// @todo Revisit after https://www.drupal.org/project/drupal/issues/2359901
22+
// @todo Revisit after https://www.drupal.org/project/drupal/issues/2403359
23+
$entity = $route_match->getParameter('entity');
24+
if ($entity instanceof SearchPageInterface) {
25+
$variables['current_page_title'] = $entity->getPlugin()->suggestedTitle();
26+
}
27+
else {
28+
$variables['current_page_title'] = Drupal::service('title_resolver')->getTitle(Drupal::request(), $route_match->getRouteObject());
29+
}
30+
// Since we are printing the 'Current Page Title', add the URL cache context.
31+
// If we don't, then we might end up with something like
32+
// "Home > Articles" on the Recipes page, which should read "Home > Recipes".
33+
$variables['#cache']['contexts'][] = 'url';
34+
}

0 commit comments

Comments
 (0)