I have a route that renders a node. Unfortunately in the breadcrumb the route title is rendered rather than the node title. When I preprocess in hook_preprocess_breadcrumb() inside my module only the preceding links are available inside $variable (not the current route title).
However, if I go to do hook_preprocess_breadcrumb() in my theme, the route title is inside $variables. So I could change it there but I want the functionality to be encapsulated inside my module, not split between module and theme.
I tried to create my own custom breadcrumb builder but I don't want to build it from scratch as there is some complex functionality built by other developers. I want to get the current breadcrumbs and then just replace the last one (the current page title) with my own.
I tried hook_system_breadcrumb_alter() as well but again the current page title is not showing up in variables inside my module.
<?php
class DefaultProductListBreadcrumbService implements BreadcrumbBuilderInterface {
/**
* Whether this breadcrumb builder should be used to build the breadcrumb.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*
* @return bool
* TRUE if this builder should be used or FALSE to let other builders
* decide.
*/
public function applies(RouteMatchInterface $route_match) {
// TODO: Implement applies() method.
return true;
}
/**
* Builds the breadcrumb.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*
* @return \Drupal\Core\Breadcrumb\Breadcrumb
* A breadcrumb.
*/
public function build(RouteMatchInterface $route_match) {
// TODO: Implement build() method.
$breadcrumb = new Breadcrumb();
$breadcrumb->addLink(Link::createFromRoute('Home', '<front>'));
return $breadcrumb;
}
}
For reference, I'm using bootstrap as the base theme with multiple sub themes (it's a multisite). I can't find anywhere that's adding the page title in the theme. I'm also using easy_breadcrumb module but I checked there and the page title is also not shown there.