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.
In #2987339: Allow path-based breadcrumb overrides it was made possible to override a generated breadcrumb trail based on the current page's path. I think it would be great to be able to introduce wildcards in the paths. E.g. if you have path with contextual arguments. My own use case are path with contextual dates with path like "/2019/01/01", and I would like to get month names instead of "01" like:
2019 > January > 01
However, instead of writing hardcoded paths for every possible year it would be great to be able to instert wildcards like:
/*/01::January
/*/02::February
etc
Comment | File | Size | Author |
---|---|---|---|
#23 | Result.png | 91.99 KB | SivaprasadC |
#23 | Configuration.png | 48.41 KB | SivaprasadC |
#22 | easy_breadcrumb-regex_custom_paths-3051106-22.patch | 4.79 KB | callumgare_ix |
|
Comments
Comment #2
Greg BoggsSounds awesome :)
Comment #3
callumgare_ixI also wanted this so I wrote a patch :)
Comment #4
callumgare_ixOops, I accidentally overwrote the original issue description and I don't have permission to revert changes so re-editing it back to the original text.
Comment #5
callumgare_ixMessed it up again, sorry new to this!
Comment #6
tatarbjThanks @callumgare_ix for the patch, i've just cleaned it up and let's see now how it behaves with our tests :)
Comment #7
tatarbjI think the description is OK now, isn't it?
Comment #8
tatarbjJust saying, we can help you in a bit more efficient way on drupal slack under #breadcrumb_solutions - come and join us ;)
Comment #9
tatarbjOk, code passes current test coverage, next step is to extend the tests.
Comment #10
callumgare_ix@tatarbj Thanks for that! I've found a few bugs so updating the patch. Since I'm adding this feature in the course of some payed work I can't work on adding tests at the moment but will hopefully have to to revisit this soon and I'll probably take you up on your offer of some help via the slack group then :)
Comment #11
tatarbjAwesome, feel free to ping me :)
Could you also attach an interdiff to see the exact changes between the patches under #6 and #10?
Comment #12
kwinten.hardies CreditAttribution: kwinten.hardies commentedHi,
How is it used? For instance, I have a path /news/belgium/title_of_article:
I can't figure it out how to use it with the patch.
I have tried:
regex!/news/belgium/\.* :: News|/news :: Belgium | /belgium
But no success.
Can you assist me please?
Thank you
Comment #13
tatarbjDear kwinten.hardies,
this functionality is still under development and not available by the module itself (maybe by applying the patch, but not finalized and clear yet).
Next time having support questions, please file a new issue and ask it there instead of under a feature request one.
Thank you in advance!
Regards,
Balazs.
Comment #14
callumgare_ix@tatarbj Sure thing, I've broken 3051106-10.patch into multiple diffs so to apply to master you would first apply 3051106-4.patch then 3051106-14.patch.
@kwinten.hardies I presume you've already applied the patch? Looking at your pattern I notice you've escaped the dot. The regex implementation is standard php PCRE syntax so what you currently have would match:
/news/belgium/.
/news/belgium/
/news/belgium/...
I think what you're trying to do is "/news/belgium/.*" but be aware that this would also match multiple levels as well as no characters:
/news/belgium/cake
/news/belgium/fire/tree
/news/belgium/.
/news/belgium/454
/news/belgium/
If you just want it to match one level that would be "/news/belgium/[^/]+" to match one or more of any characters except "/":
/news/belgium/cake
/news/belgium/fire
/news/belgium/.
/news/belgium/454
Comment #15
kwinten.hardies CreditAttribution: kwinten.hardies commented@callumgare_ix thank you very much. I indeed applied the patch and based myself on the description under the custom path field. Thank you.
Comment #16
callumgare_ix@kwinten.hardies Cool, that suggests the description needs to be made a bit clearer. Only it's already super long so I don't really want to make it longer. I'll have a think about that one 🤔
Comment #17
Greg BoggsThis patch is great!
I don't mean to be picky, but as the poor programmer in the room, if we ever have a bug related to these bits, it will be difficult for me. Can we rewrite this line without the ternary operator?
+ if ($is_regex ? preg_match("|" . $custom_path . "|", $path, $url_group_matches) : $path == $custom_path) {
Comment #18
kwinten.hardies CreditAttribution: kwinten.hardies commented@callumgare_ix, following your regex comments, there is an mistake in the documentation for the regex paths. It's described as followed: "regex!/news/archive/\d{4} :: News | /news :: Archive | /news/archive". But for me it was only working when I removed the first slash in the path right after the regex!. So it was "regex!news/archive/\d{4} :: News | /news :: Archive | /news/archive".
And the patch removes the " Include the current page as a segment in the breadcrumb" option. Maybe we can work together for the patch to work with all the options of easy breadcrumb?
After all It's a very useful patch.
Comment #19
diamondseaAgree with @greg on #17 about the terinary conditional. Maybe use:
Comment #20
iinterval CreditAttribution: iinterval commentedI have same problem on my site https://www.wishhow.com/ missing breadcrumbs and don't know how to solve this problem I already try many options to solve this but not solve yet.
Comment #21
tonytheferg CreditAttribution: tonytheferg commentedI think I opened a duplicate here https://www.drupal.org/project/easy_breadcrumb/issues/3096006.
Comment #22
callumgare_ixSorry it’s taken me awhile to get back to this. I’ve made some changes based on feedback and created a new patch. Since master has changed since I started in the mean time this patch applies directly to master (currently commit 2fa0b4d19b46916dc72aff803b1fbd428ffb8335) rather than being applied on top of the previous patches.
@greg-boggs @diamondsea That’s not picky at all. Terseness shouldn’t come at the cost of readability. I’ve modified it to use something very similar to diamondsea‘s proposal.
@kwinten.hardies > leading slash
Thanks! Yep, that’s a bug. I’ve changed it so it should have a leading slash to match non-regex custom paths. Thus the comments should now be correct.
@kwinten.hardies > patch removes the "Include the current page as a segment in the breadcrumb" option
This patch doesn’t change that behavior. Custom paths (regex ones or not) will ignore that option. Which in my opinion is how it should work. Consider this situation: For all of your paths you want to have the current page included in the breadcrumb. Except for one of them you want to have a custom path and you want to be able to customise what that current page link or text looks like. If the “Include the current page...” option applied to custom paths then it would add a link to the current page at the end even though you’re specifying something else to use for the current page link.
Comment #23
SivaprasadC CreditAttribution: SivaprasadC as a volunteer and at DrupalPartners for Innoppl Technologies Pvt. Ltd commented@callumgare_ix Thanks for the path. I have applied it successfully. it's working as expected for my use case.
URL: http://example.com/checkout/1074/login
Configuration: regex!/checkout/([^/]*)/login :: Checkout | /checkout/$1
PFA for your reference. Thank you all.
Comment #24
callumgare_ix@SivaprasadC Thanks for that! Great to hear :3
Comment #25
Fool2 CreditAttribution: Fool2 commented@callumgare_ix, RE: the "Include the current page as a segment in the breadcrumb" option-- it appears that on my paths using the regex option, it ALWAYS adds the current path at the end, even though I have the configuration setting unchecked.
This may be a problem not specific to this patch
Comment #27
Neslee Canil PintoTested this, and it works fine for me. Committed. Thanks
Comment #28
SivaprasadC CreditAttribution: SivaprasadC as a volunteer and at Tech Mahindra for Drupal India Association commented