File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
apps/drupal-default/particle_theme/includes Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments