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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

matsbla created an issue. See original summary.

Greg Boggs’s picture

Sounds awesome :)

callumgare_ix’s picture

Issue summary: View changes
FileSize
4.42 KB

I also wanted this so I wrote a patch :)

callumgare_ix’s picture

Issue summary: View changes

Oops, 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.

callumgare_ix’s picture

Issue summary: View changes

Messed it up again, sorry new to this!

tatarbj’s picture

Status: Active » Needs review
FileSize
4.42 KB

Thanks @callumgare_ix for the patch, i've just cleaned it up and let's see now how it behaves with our tests :)

tatarbj’s picture

I think the description is OK now, isn't it?

tatarbj’s picture

Just saying, we can help you in a bit more efficient way on drupal slack under #breadcrumb_solutions - come and join us ;)

tatarbj’s picture

Issue tags: +Needs tests

Ok, code passes current test coverage, next step is to extend the tests.

callumgare_ix’s picture

FileSize
4.65 KB

@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 :)

tatarbj’s picture

Awesome, feel free to ping me :)
Could you also attach an interdiff to see the exact changes between the patches under #6 and #10?

kwinten.hardies’s picture

Hi,

How is it used? For instance, I have a path /news/belgium/title_of_article:

  • /news must be a link to a view page (/news)
  • /belgium/ must be a link to a node that has a path alias of /belgium
  • /title_of_article is the title of the article, no link needed

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

tatarbj’s picture

Dear 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.

callumgare_ix’s picture

FileSize
3.88 KB

@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

kwinten.hardies’s picture

@callumgare_ix thank you very much. I indeed applied the patch and based myself on the description under the custom path field. Thank you.

callumgare_ix’s picture

@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 🤔

Greg Boggs’s picture

This 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) {

kwinten.hardies’s picture

@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.

diamondsea’s picture

Agree with @greg on #17 about the terinary conditional. Maybe use:

if ( ($is_regex && preg_match("|" . $custom_path . "|", $path, $url_group_matches) ) 
      || 
     (!$is_regex && $path == $custom_path)
    ) {
iinterval’s picture

I 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.

tonytheferg’s picture

callumgare_ix’s picture

Sorry 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.

SivaprasadC’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +RTBC
FileSize
48.41 KB
91.99 KB

@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.

callumgare_ix’s picture

@SivaprasadC Thanks for that! Great to hear :3

Fool2’s picture

@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

Neslee Canil Pinto’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs tests, -RTBC

Tested this, and it works fine for me. Committed. Thanks

SivaprasadC’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.