Drupal seems to be adding some default breadcrumbs that come from the URL. How can I disable this feature? I don't see it in configuration but maybe I'm looking in the wrong place.
2 Answers
The default breadcrumb builder is defined in the system services file and has the priority 0:
system.services.yml
system.breadcrumb.default:
class: Drupal\system\PathBasedBreadcrumbBuilder
arguments: ['@router.request_context', '@access_manager', '@router', '@path_processor_manager', '@config.factory', '@title_resolver', '@current_user', '@path.current']
tags:
- { name: breadcrumb_builder, priority: 0 }
If you want to turn off the default breadcrumb builder you define one with a higher priority. This is an example for taxonomy terms:
taxonomy.services.yml
services:
taxonomy_term.breadcrumb:
class: Drupal\taxonomy\TermBreadcrumbBuilder
arguments: ['@entity.manager']
tags:
- { name: breadcrumb_builder, priority: 1002 }
With the method applies()
you choose for which routes the breadcrumb builder should be used:
TermBreadcrumbBuilder::applies()
public function applies(RouteMatchInterface $route_match) {
return $route_match->getRouteName() == 'entity.taxonomy_term.canonical'
&& $route_match->getParameter('taxonomy_term') instanceof TermInterface;
}
The breadcrumb manager checks all applies() methods, starting with the highest priority, until it reaches the default breadcrumb builder, which applies for all routes:
PathBasedBreadcrumbBuilder::applies()
public function applies(RouteMatchInterface $route_match) {
return TRUE;
}
In D8, breadcrumbs are now blocks. They can be disabled in Block Layout.
-
Hi but I dont want to delete all of the breadcrumbs, just the ones that drupal core adds– DianaMay 19, 2017 at 21:29
-
hook_system_breadcrumb_alter
you can use to override things.