Skip to content

Commit

Permalink
fix/breadcrumb hook improvement (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
jryanconklin authored Aug 27, 2020
1 parent ec3996c commit 0498719
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions apps/drupal-default/particle_theme/includes/navigation.theme.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,31 @@
* @file
* Functions to support theming menu navigation in the Particle theme.
*/

use Drupal\search\SearchPageInterface;

/**
* Implements hook_preprocess_breadcrumb().
*/
function particle_preprocess_breadcrumb(&$variables) {
// Taken from Umami theme
// We are creating a variable for the Current Page Title, to allow us to print
// it after the breadcrumbs loop has run.
$route_match = Drupal::routeMatch();
// Search page titles aren't resolved using the title_resolver service - it
// will always return 'Search' instead of 'Search for [term]', which would
// give us a breadcrumb of Home >> Search >> Search.
// @todo Revisit after https://www.drupal.org/project/drupal/issues/2359901
// @todo Revisit after https://www.drupal.org/project/drupal/issues/2403359
$entity = $route_match->getParameter('entity');
if ($entity instanceof SearchPageInterface) {
$variables['current_page_title'] = $entity->getPlugin()->suggestedTitle();
}
else {
$variables['current_page_title'] = Drupal::service('title_resolver')->getTitle(Drupal::request(), $route_match->getRouteObject());
}
// Since we are printing the 'Current Page Title', add the URL cache context.
// If we don't, then we might end up with something like
// "Home > Articles" on the Recipes page, which should read "Home > Recipes".
$variables['#cache']['contexts'][] = 'url';
}

0 comments on commit 0498719

Please sign in to comment.