Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
E.g.
Node A:
Product Category: Bikes > Fixed Gear Bikes
Node B:
Product Category: Scooters
Now if I want to setup custom breadcrumbs and I want to use something like Home > [root term] > [node_title] I'd use something like [node:product_category:root] to get the root category term.
This works for Node A as it will show the crumb as Home > Bikes > Node A Title.
Node B however is broken and it does not render the root term. Perhaps because Scooters itself is a root term and does't have any parents?
Why is this? Is it fixable or intended functionality?
Comment | File | Size | Author |
---|---|---|---|
#1 | term-token-real-root-2050421-1.patch | 1.71 KB | geophysicist |
Comments
Comment #1
geophysicist CreditAttribution: geophysicist commentedHere is patch. Added possibility to use real root. Just insert real-root token instead root
Comment #2
Dave ReidIt sounds like you want a token like [term:root-or-current] that has logic depending if the term itself is a root term or not. You can easily create custom tokens via the core token APIs (hook_token_info() and hook_tokens(), or via the Custom tokens module). I cannot change the behavior of the [term:root] token to fit this need.
Comment #3
valderama CreditAttribution: valderama commentedHere is an implementation of the said hooks to add this [term:root-or-current] token: http://dropbucket.org/node/1535
In my opinion this should be the default behavior of the [term:root] token. I would be glad if this get into future version, where backwards compatibility can be broken.
Or - as a less philosophical solution - add this extra token to the token module.
Comment #4
zwerg CreditAttribution: zwerg commentedBoth patches won't fix this issue...
Comment #5
mrweiner CreditAttribution: mrweiner commentedTo implement the described custom token in Drupal 8, use the following in your custom module:
Comment #6
osopolarI was surprised as I discovered that [term:root] is only set if the current term is not a root term. I would like to see that behavior implemented, but ss of #2, it may not get fixed. If that is still the case, at least it should be mentioned in the token description, that the token would be empty if term itself is a root term.
It would be the same for other root tokens like the the menu link's root.
BTW: The code in #3 and #5 will work only for the term name/lable, but not for chaining, as it misses following code (see D7 patch):