function umami_preprocess_breadcrumb

Same name in other branches
  1. 9 core/profiles/demo_umami/themes/umami/umami.theme \umami_preprocess_breadcrumb()
  2. 8.9.x core/profiles/demo_umami/themes/umami/umami.theme \umami_preprocess_breadcrumb()
  3. 10 core/profiles/demo_umami/themes/umami/umami.theme \umami_preprocess_breadcrumb()

Implements hook_preprocess_breadcrumb().

File

core/profiles/demo_umami/themes/umami/umami.theme, line 99

Code

function umami_preprocess_breadcrumb(&$variables) : void {
    // 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';
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.