Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
13

Probably a little late to respond, but I came across this thread this morning whilst looking for a way to override the breadcrumb in Drupal 7, it helped a little so I thought I would add my solution. This creates extra crumbs based on content types and adds the current page to the crumb. I'm using this to add a crumb to a filtering view seen before the ...


10

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 with advice from this post, but then I clicked around and noticed the same breadcrumbs on every page. Long story short, make sure to set some cache contexts ...


9

This can be accomplished by overriding theme_breadcrumb() in your theme's template.php An example implementation: function mytheme_breadcrumb($breadcrumb) { if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) { $breadcrumb = array(); $breadcrumb[] = l(t('Home'), '<front>'); $breadcrumb[] = l(t('Blog'), '...


9

hook_menu_breadcrumb_alter() does not work on pages where drupal_set_breadcrumb() has been called before. hook_menu_breadcrumb_alter() is invoked from menu_get_active_breadcrumb(). This is called from drupal_get_breadcrumb(), but only if no breadcrumb has been previously set with drupal_set_breadcrumb(). It does not look like drupal_set_breadcrumb() is ...


8

The stable Drupal 7 version of Custom Breadcrumbs is currently in the 1.x branch; support for Views has only been added in the 2.x branch, for which there is no stable release for either version (there's an RC available for Drupal 6 but only a dev version for Drupal 7). I think your options are: Try the 7.x-2.x-dev branch and report any problems you find ...


8

Yeah breadcrumb changed and the documentation must be update. Likewise, I don't really understand what the services.yml file is doing in this regard, there's no documentation anywhere for this. For Drupal 8: The Crash Course | DrupalCon Amsterdam 2014, awesome presentation, about 47:02: Drupal 8 in 2 steps: Build a tool Wire it up The wiring may ...


8

Update 2016 Drupal 8 The Documentation states that you must return an instance of the breadcrumb class. If you are having trouble getting it to work. here is the solution that worked for me. <?php //modules/MY_MODULE/src/MyBreadcrumbBuilder.php namespace Drupal\registration; use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; use Drupal\Core\...


7

I normally stick that logic in hook_preprocess_page(), it runs late enough in the page build to not be overwritten by anything else. You can still get access to the node object by using the menu_get_object() function: function MYTHEME_preprocess_page(&$vars) { if ($node = menu_get_object()) { // We're on a node page... drupal_set_breadcrumb($...


7

Don't forget caching The render cache was changed fairly late in the D8 development cycle, and so it's not mentioned in the d8ftw series, or the other answers to this question. The Cache API documentation refers specifically to render arrays, but all of those instructions apply equally to Breadcrumbs. Breadcrumbs have a toRenderable() method, Drupal ...


6

Some themes - like Zen - provide this option, so check under Appearance -> Settings. If your theme doesn't offer the option, you can edit your theme's page.tpl.php - simply add $title after the $breadcrumb variable. Alternatively you could override theme_breadcrumb().


6

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].[display_id]. You can list the existing routes with Drupal Console: drupal router:debug


5

Check out the Custom Breadcrumbs module which has support for Views. Here is a quote about it (from the module's project page): Custom Breadcrumbs 1: Allows administrators to set up parametrized breadcrumb trails for any node type. This allows CCK-style node types to have "Home > User Blog > 2005 > January" style breadcrumbs on the node view page ...


5

There is also an alter hook for breadcrumbs, where you can alter them in a non-theme specific way, in case the breadcrumbs are also used somewhere else. I've implemented this in a project: /** * Implements hook_system_breadcrumb_alter(). */ function yourmodule_system_breadcrumb_alter(array &$breadcrumb, RouteMatchInterface $route_match, array $...


5

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 module/profile services file: e.g., mymodule/mymodule.services.yml services: mymodule.breadcrumb: class: Drupal\mymodule\MyModuleBreadcrumbBuilder tags: ...


5

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 priority of your breadcrumb service to a value higher than this should get Drupal to use your breadcrumb rather than the default one. Something like this should do ...


5

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($variables['breadcrumb']); ... } You could also solve this in the template file, by skipping the first item in {{ breadcrumb }} If you want module only ...


4

I think you could use theme_breadcrumb($variables) in your template.php to remove duplicates. Code could be something like this: themeName_breadcrumb($variables) { [...] $breadcrumbs = array_unique($variables['breadcrumb']); [...] }


4

A simple custom solution would be to add a function like this in your theme's template.php file: function MYTHEME_preprocess_node(&$variables) { //Retrieve current breadcrumb $breadcrumbs = drupal_get_breadcrumb(); //Add the title without link $breadcrumbs[] = $variables['node']->title; //OR add the title with a link $breadcrumbs[] = l($...


4

You could also use the Menu breadcrumb module to do this (it has D6 and D7 versions too). It allows you to "Append the page title to the breadcrumb (either as a clickable url or not)" See this tutorial: Tutorial - How to Work and Style Breadcrumbs in Drupal 7


4

There is a module for that (well more than one): http://drupal.org/project/custom_breadcrumbs http://drupal.org/project/taxonomy_breadcrumb Probably would choose custom breadcrumbs due to its flexibility, and ability to craft breadcrumbs for the rest of your site as well.


4

"Switch on node type" is like a switch($case){} statement in PHP (and other languages). After selecting "Switch on node type" in Hansel, you will need to provide the *machine_name* of the node-type in the "Name" field that Hansel presents. For instance, you can enter one of the following in the "Name" field: article -- will target Article nodes ...


4

Your nodes contain apostrophe in their title. Node titles will be passed through check_plain() function and it uses htmlspecialchars() function to convert the quotes to HTML entities. You may try by decoding them back function myowntheme_breadcrumb($variables) { $sep = ' &gt; '; if (count($variables['breadcrumb']) > -1) { return ...


4

Crumbs provides a "Breadcrumb (Crumbs)" block that you should be able to use.


4

If you are using Drupal 7, then you can use: Path Breadcrumbs Context path breadcrumb Path breadcrumbs module helps you to create breadcrumbs for any page with any selection rules and load any entity from the URL! This is a plugin module for the context module. It takes the request URI part of the URL of the current page (for example /our-...


4

There is a patch for the Path Breadcrumbs module that adds a setting to disable other breadcrumbs: https://www.drupal.org/node/2483091 The patch allows an easy one click disabling of other breadcrumbs. Here is a screenshot of the setting on the patch breadcrumbs settings page (admin/structure/path-breadcrumbs/settings) as it is in the current version of ...


4

There is another way to achieve this. /** * Implements hook_preprocess_breadcrumb(). */ function theme_name_preprocess_breadcrumb(&$variables){ if(($node = \Drupal::routeMatch()->getParameter('node')) && $variables['breadcrumb']){ $variables['breadcrumb'][] = array( 'text' => $node->getTitle() ); } } And then ...


4

If anyone else is looking for this, here is one way to solve it: In template.php add the following function function theme_breadcrumb($variables){ // get an array with all the breadcrumbs (and their html) $breadcrumb = $variables['breadcrumb']; // remove the html from the last one and put it into new variable $cur_page_brdcrmb = strip_tags(...


4

By default, the variable {{title}} will not avaliable to breadcrumb.html.twig. You have to to use HOOK_preprocess_breadcrumb in your .theme file. P.S: In D8, it is bad practice only if you try to display the data from preprocesser function. It is nothing wrong of you try to add extra variable in preprocesser. Here more clarification https://www.drupal.org/...


4

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>'));


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