I want to add another element to breadcrumb.
I have:
Home > Node Title
I want to add another link between the two elements like:
Home > Link to view > Node Title
I have tried with hook_system_breadcrumb_alter
like the following:
/**
* Implements hook_system_breadcrumb_alter().
*/
function MyModules_system_breadcrumb_alter(Breadcrumb &$breadcrumb, RouteMatchInterface $route_match, array $context) {
if ( $route_match->getRouteName() === 'entity.node.canonical'){
$node = $route_match->getParameter('node');
if ($node instanceof Drupal\node\Entity\Node && $node->getType() === 'my_node_type'){
// Get the listing view url.
$listing_url = Url::fromRoute('view.my_view_id.my_display_id');
// Add the listing url to breadcrumbs.
$breadcrumb->addLink(Link::fromTextAndUrl(t('Link to view'), $listing_url));
}
}
}
But i get Home > Node Title > Link to view
instead of Home > Link to view > Node Title
My question is how can i change the order of the last two breadcrumbs elements?