In Drupal 8, how can one determine the Menu Link Title of a node, given its URL and other information like its route & parameters?
This is to modify the core path-based breadcrumbs (
PathBasedBreadcrumbBuilder.php) to use the Menu Link Title of a node, as breadcrumb link text, rather than the node's Title field. This would have to be a common requirement, since the default D8 breadcrumbs would be very long in deep menus with wordy titles. For example, we would need:
Home > Design > Drupal
instead of the D8 default:
Home > Introduction to Our Design Services > Drupal 8: The Best CMS for Everything
for all nodes in the "Drupal" sub-menu.
The default breadcrumb service method
PathBasedBreadcrumbBuilder::build uses a bunch of injected services to look up & check routes to each ancestor pathname of the node URL, then ultimately
TitleResolver::getTitle to get the titles for those routes. We would just need a way of looking up the corresponding
MenuLinkContent instead so we could then get the menu title via
I have tried to outline the problem for the Drupal Module Development forum (change Breadcrumbs from Node Title to Menu Link Title) but got no response when asking how to simply bridge the gap between the space of URLs/routes and the space of menu link content. Maybe this means it's not possible without a traversal of the menu: if so I would deeply appreciate some idea of where to start with that approach.