Skip to content

Commit

Permalink
Adding a variable for page title for breadcrumbs and printing it as t…
Browse files Browse the repository at this point in the history
…he last breadcrumb.
  • Loading branch information
Mark Conroy committed Jan 5, 2018
1 parent d164a65 commit 8456005
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
30 changes: 30 additions & 0 deletions templates/components/navigation/breadcrumb.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{#
/**
* @file
* Theme override for a breadcrumb trail.
*
* Available variables:
* - breadcrumb: Breadcrumb trail items.
*/
#}
{% if breadcrumb %}
<nav class="breadcrumb" role="navigation" aria-labelledby="system-breadcrumb">
<h2 id="system-breadcrumb" class="visually-hidden">{{ 'Breadcrumb'|t }}</h2>
<ol>
{% for item in breadcrumb %}
<li>
{% if item.url %}
<a href="{{ item.url }}">{{ item.text }}</a>
{% else %}
{{ item.text }}
{% endif %}
</li>
{% endfor %}
{#
Once the breadcrumb loop completes, we add the current page title.
This variable is created in umami.theme.
#}
<li> {{ current_page_title }}</li>
</ol>
</nav>
{% endif %}
12 changes: 12 additions & 0 deletions umami.theme
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ function umami_theme_suggestions_block_alter(array &$suggestions, array $variabl
array_splice($suggestions, 1, 0, 'block__bundle__' . $variables['elements']['content']['#block_content']->bundle());
}
}

/**
* Implements hook_preprocess_breadcrumb().
*/
function umami_preprocess_breadcrumb(&$variables) {
// We are creating a variable for the Current Page Title, to allow us to print
// it after the breadcrumbs loop has run.
$request = \Drupal::request();
if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
$variables['current_page_title'] = \Drupal::service('title_resolver')->getTitle($request, $route);
}
}

0 comments on commit 8456005

Please sign in to comment.