comparison core/profiles/demo_umami/themes/umami/umami.theme @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
5 * Functions to support theming in the Umami theme. 5 * Functions to support theming in the Umami theme.
6 */ 6 */
7 7
8 use Drupal\Component\Utility\Html; 8 use Drupal\Component\Utility\Html;
9 use Drupal\Core\Form\FormStateInterface; 9 use Drupal\Core\Form\FormStateInterface;
10 use Symfony\Cmf\Component\Routing\RouteObjectInterface; 10 use Drupal\search\SearchPageInterface;
11 11
12 /** 12 /**
13 * Implements hook_preprocess_HOOK() for HTML document templates. 13 * Implements hook_preprocess_HOOK() for HTML document templates.
14 * 14 *
15 * Adds body classes if certain regions have content. 15 * Adds body classes if certain regions have content.
66 * Implements hook_preprocess_breadcrumb(). 66 * Implements hook_preprocess_breadcrumb().
67 */ 67 */
68 function umami_preprocess_breadcrumb(&$variables) { 68 function umami_preprocess_breadcrumb(&$variables) {
69 // We are creating a variable for the Current Page Title, to allow us to print 69 // We are creating a variable for the Current Page Title, to allow us to print
70 // it after the breadcrumbs loop has run. 70 // it after the breadcrumbs loop has run.
71 $request = \Drupal::request(); 71 $route_match = \Drupal::routeMatch();
72 if ($route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) { 72 // Search page titles aren't resolved using the title_resolver service - it
73 // Search page titles aren't resolved using the title_resolver service - it 73 // will always return 'Search' instead of 'Search for [term]', which would
74 // will always return 'Search' instead of 'Search for [term]', which would 74 // give us a breadcrumb of Home >> Search >> Search.
75 // give us a breadcrumb of Home >> Search >> Search. 75 // @todo Revisit after https://www.drupal.org/project/drupal/issues/2359901
76 // @see https://www.drupal.org/project/drupal/issues/2359901 76 // @todo Revisit after https://www.drupal.org/project/drupal/issues/2403359
77 // @see https://www.drupal.org/project/drupal/issues/2403359 77 $entity = $route_match->getParameter('entity');
78 if (($entity = $request->attributes->get('entity')) && $entity->getEntityTypeId() === 'search_page') { 78 if ($entity instanceof SearchPageInterface) {
79 $variables['current_page_title'] = $entity->getPlugin()->suggestedTitle(); 79 $variables['current_page_title'] = $entity->getPlugin()->suggestedTitle();
80 } 80 }
81 else { 81 else {
82 $variables['current_page_title'] = \Drupal::service('title_resolver')->getTitle($request, $route); 82 $variables['current_page_title'] = \Drupal::service('title_resolver')->getTitle(\Drupal::request(), $route_match->getRouteObject());
83 }
84 } 83 }
85 // Since we are printing the 'Current Page Title', add the URL cache context. 84 // Since we are printing the 'Current Page Title', add the URL cache context.
86 // If we don't, then we might end up with something like 85 // If we don't, then we might end up with something like
87 // "Home > Articles" on the Recipes page, which should read "Home > Recipes". 86 // "Home > Articles" on the Recipes page, which should read "Home > Recipes".
88 $variables['#cache']['contexts'][] = 'url'; 87 $variables['#cache']['contexts'][] = 'url';