Skip to content

Instantly share code, notes, and snippets.

@zviryatko
Created December 15, 2015 13:19
Show Gist options
  • Save zviryatko/cd15bd0ce3ad3c9cf89d to your computer and use it in GitHub Desktop.
Save zviryatko/cd15bd0ce3ad3c9cf89d to your computer and use it in GitHub Desktop.
Add title to breadcrumbs in Drupal 8
<?php
/**
* Implements hook_process_HOOK().
*/
function custom_preprocess_breadcrumb(&$variables) {
/** @var \Drupal\Core\Controller\TitleResolverInterface $title_resolver */
$title_resolver = \Drupal::service('title_resolver');
/** @var \Drupal\Core\Routing\CurrentRouteMatch $current_route */
$current_route = \Drupal::service('current_route_match');
$title = $title_resolver->getTitle(\Drupal::request(), $current_route->getRouteObject());
$variables['breadcrumb'][] = ['text' => (string) $title];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment