Skip to main content
15 votes
Accepted

Breadcrumbs are cached

Breadcrumbs for nodes have no cache tags. The reason is that the node entity has no specific breadcrumb builder. The generic path based breadcrumb builder gets the title from the title resolver and is ...
4uk4's user avatar
  • 101k
10 votes
Accepted

How to alter breadcrumbs from my controller in my module?

To customize your Breadcrumbs you need to take full control of the Breadcrumb for that particular route with your own Breadcrumb Builder service. To do this, you need to create an entry in your ...
Decipher's user avatar
  • 3,722
10 votes

How do you implement a breadcrumb?

Here we go again. These answers are mostly right. One thing you can't forget about is "cache tags" and "cache contexts". I was setting up a taxonomy term on a node as a breadcrumb. I got it working ...
Jon Pugh's user avatar
  • 149
10 votes
Accepted

How to do a custom taxonomy breadcrumb

The taxonomy module provides a default breadcrumb service and if you have a look at the declaration of this in the taxonomy.services.yml file you will see it has a priority of 1002. Setting the ...
Stephen Cox's user avatar
10 votes
Accepted

How do I programmatically remove one breadcrumb link?

Drupal 7 and Drupal 8 are more or less the same in some aspects. If you use preprocess_breadcrumb in your theme, you would do function my_theme_preprocess_breadcrumb(&$variables) { array_pop($...
googletorp's user avatar
  • 35.4k
9 votes
Accepted

How to disable breadcrumbs for certain pages?

Your Breadcrumb is a block that you place in Block Lay-out. Then just change its visibility.
Vagner's user avatar
  • 2,503
7 votes
Accepted

Check the current page is a view

You could use the name of the current route: $current_route_name = \Drupal::service('current_route_match')->getRouteName(); The route names from views are built like this view.[view_name].[...
4uk4's user avatar
  • 101k
5 votes
Accepted

Adding a non-link element to the end of the breadcrumb

You can do almost like in your suggestion. You just need to use '<none>' instead of 'nothing!'. $b->addLink(Link::createFromRoute($this->t('Recipe'), '<none>'));
Alex Afanasiev's user avatar
5 votes

Problem with HOOK_preprocess_breadcrump (Caching?)

Change the cache context from 'url.path' to 'url' function xxx_preprocess_breadcrumb(&$variables) { ... $variables['breadcrumb'] = array( array( 'text' => 'some text', ...
Ivan Rodriguez's user avatar
5 votes

How do you implement a breadcrumb?

There is another way to achieve this. /** * Implements hook_preprocess_breadcrumb(). */ function theme_name_preprocess_breadcrumb(&$variables){ if(($node = \Drupal::routeMatch()->...
Sachin's user avatar
  • 436
5 votes

How can I add Taxonomy Term to a Node's Breadcrumb?

Themers who don't want to use a custom module to implement a BreadcrumbBuilder can change the breadcrumbs in a preprocess hook. Example how you can add a link before the last link: function ...
4uk4's user avatar
  • 101k
5 votes

How can I add Taxonomy Term to a Node's Breadcrumb?

We can implement custom breadcrumb either via module or via HOOK_preprocess_breadcrumb. Via HOOK_preprocess_breadcrumb: Add this in your YOURTHEME.theme /** * Implements HOOK_preprocess_breadcrumb(...
Rishi Kulshreshtha's user avatar
5 votes
Accepted

Prevent path based breadcrumb in theme, or, don't show breadcrumbs for 403/404 responses?

You could add a visibility condition to the breadcrumb block. For 404 there is this module block_in_page_not_found and if you negate the condition the block is displayed on all pages other than 404's: ...
4uk4's user avatar
  • 101k
4 votes
Accepted

Breadcrumb Preprocess from Module

Preprocess hooks work in themes and modules. It doesn't matter where you put it, the only difference is, that modules have higher priority. What you have to do is to work on caching. Because of the ...
4uk4's user avatar
  • 101k
4 votes

How to redirect a user to the current page?

Like this you get the actual path: \Drupal::service('path.current')->getPath() and then you just use it as: $current_page_link = new Drupal\Core\Link('So here you are', Drupal\Core\Url::fromUri('...
rémy's user avatar
  • 5,720
4 votes

Breadcrumbs are cached

I am very sorry that I don't (yet) have the "50 reputation" to comment on 4x4's excellent answer above, but we have a pathogical case already identified in that same issue queue... It would be great ...
rphair's user avatar
  • 169
4 votes
Accepted

Default Breadcrumb is not working in bootstrap drupal 8?

The twig code doesn't work and you don't need it for the breadcrumb block to be available in the block layout. It's the other way, first you assign the breadcrumb block in for example the Highlighted ...
4uk4's user avatar
  • 101k
4 votes

How can I override certain breadcrumb segments?

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 ...
4uk4's user avatar
  • 101k
4 votes
Accepted

Which implementation is better for custom breadcrumb and why?

When you build a module which for example provides a new content or entity type you can include a breadcrumb builder, because you might have data fields that the standard breadcrumb builder doesn't ...
4uk4's user avatar
  • 101k
4 votes
Accepted

Taxonomy term route name?

Since taxonomy terms are entities, you can simply do this: $link = $term->toLink(); $breadcrumb->addLink($link); As a side-note, the route name for taxonomy terms is "entity.taxonomy_term....
oknate's user avatar
  • 14.4k
4 votes
Accepted

How do I customize hierarchical breadcrumbs?

In D8 the hierarchy of breadcrumbs is by default path based, so you have to change the path for the second level from /service1 to /services/service1 Or install a module to build the hierarchy based ...
4uk4's user avatar
  • 101k
4 votes
Accepted

How can I alter Easy Breadcrumb?

As it mentioned in the comment section the $variables should passed by reference take a look at hook_preprocess_HOOK documentation page. And also read about strpos to adapt your condition, here is an ...
berramou's user avatar
  • 7,245
3 votes
Accepted

How to include menu item in breadcrumb

Menu Breadcrumb might be what you're looking for.
Kevin's user avatar
  • 27.9k
3 votes
Accepted

How to redirect a user to the current page?

You can try use Drupal\Core\Link; use Drupal\Core\Url; $redirect_to_same_page = Link::fromTextAndUrl('Same page', Url::fromUri('base:' .\Drupal::service('path.current')->getPath())); ...
Shreya Shetty's user avatar
3 votes
Accepted

Add a breadcrumb to a view page?

You should create a custom module (use core >= 8.3). Use this code as a base to start: custom_breadcrumb.info.yml name: 'Custom breadcrumbs' description: 'Custom breadcrumbs implementation' package: ...
Roger's user avatar
  • 228
3 votes
Accepted

Can adding a cache tag create another cache row in database

First of all you should add tags of all nodes/terms you use to build the breadcrumb. You can't set too many tags, because a tag doesn't influence how many cache entries are stored. This is only a ...
4uk4's user avatar
  • 101k
3 votes
Accepted

How do I manage a mix of menu and custom breadcrumbs?

Do I have to create my own Breadcrumb builder class? Yes, there are many places where you can modify breadcrumbs, but this is the only straightforward way. The custom breadcrumbs should have a ...
4uk4's user avatar
  • 101k
3 votes
Accepted

Getting "Call to a member function getName() on null" in custom breadcrumb

You can also use hook_system_breadcrumb_alter to achieve this: Try this: /** * Implements hook_system_breadcrumb_alter(). */ function MyModule_system_breadcrumb_alter(\Drupal\Core\Breadcrumb\...
berramou's user avatar
  • 7,245
3 votes

How do I enable breadcrumbs?

Breadcrumb block relies on URL aliases to build its content. To have your breacrumb display "Home > Tag title" when you are on your article page, you need your article URL alias to "...
misterdidi's user avatar
  • 1,051
3 votes

Disable core path based breadcrumb only for the frontend theme

Normally it's unnecessary to decorate a tagged service. You can register the extended core service class again with a different priority (in your case between the path based and the menu-based ...
4uk4's user avatar
  • 101k

Only top scored, non community-wiki answers of a minimum length are eligible