Skip to content

Instantly share code, notes, and snippets.

@rwohleb
Created October 16, 2019 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwohleb/f72fd3534ae2c1441afdb98a034c5d90 to your computer and use it in GitHub Desktop.
Save rwohleb/f72fd3534ae2c1441afdb98a034c5d90 to your computer and use it in GitHub Desktop.
D8: Breadcrumb/page links in views
<?php
/**
* Implements hook_preprocess_HOOK().
*/
function my_theme_preprocess_views_view(&$variables) {
$view = $variables['view'];
$variables['breadcrumb_links'] = \Drupal::service('breadcrumb')->build(\Drupal::routeMatch())->getLinks();
$variables['view_page_urls'] = [];
$variables['view_page_links'] = [];
if ($displays = $view->displayHandlers) {
foreach ($displays as $display_id => $display) {
if ($display instanceof \Drupal\views\Plugin\views\display\Page) {
$route_name = sprintf('view.%s.%s', $view->id(), $display_id);
$url = Url::fromRoute($route_name, [], ['set_active_class' => TRUE]);
$menu = $display->getOption('menu');
if (!empty($menu['title'])) {
$variables['view_page_urls'][$display_id] = $url;
$variables['view_page_links'][$display_id] = Link::fromTextAndUrl($menu['title'], $url);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment