No breadcrumbs built when path segents are excluded

Created on 19 August 2024, 4 months ago

Easy Breadcrumbs is not building breadcrumbs as soon as a path seg,ent is ignored and this is part of the URL. The easiest way to see this is to ignore the "node" part in a URL and visit a default node URL. This started with version 2.0.7 and is still not working in 2.0.8.

Check the following configuations in the module:
- Include the current page as a segment in the breadcrumb
- Include the front page as a segment in the breadcrumb
- Use the real page title when available
Also set `Paths to be excluded while generating segments` to `node`.

Then visit a URL like `/node/42`. This used to create a breadcrumb like `Home > My Test Page Title`. Now, this is only `Home`.

Looking at the code changes in `EasyBreadcrumbBuilder::build`, I really don't get what is happening now. The regex check against the code segments to exclude used to run on `end($path_elements)`. If it matched this last element of the path segments, then this element was removed with array_pop.

Now, the regex check is run against `$check_path`, which is the complete path. So if $path_elements has two values, "node" and "42", and the exclude regex is just "node" (to avoid an empty breadcrumb segment, since the node part doesn't lead to any page), this matches once against the whole path and 42 is removed (note that it matches the first element of the array, but the last element is removed). Then it matches again against the whole path, and "node" is removed. Then, no path elements are left, and we get just the Home link.

It works as soon as an URL alias exists, because then the regex doesn't match anymore. Of course, it also fails when you try to exclude a segment like "news" from a longer aliased URL like "/news/my-page-title". No breadcrumbs again.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany ammaletu Bonn, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ammaletu
  • πŸ‡©πŸ‡ͺGermany ammaletu Bonn, Germany
  • πŸ‡©πŸ‡ͺGermany spuky

    I guess your bug is other Peoples feature...

    and the change was in [3196198]

  • πŸ‡©πŸ‡ͺGermany spuky

    also related

  • πŸ‡©πŸ‡ͺGermany ammaletu Bonn, Germany

    I don't think this is about treating the exclusion string as a regex or not. The same thing happens if I put a regex in the exclude config instead of simply the string "node". I just tried it with "node\/[0-9]+" and still didn't get breadcrumbs beyong the Home link.

    The question is against what part of the URL the regex is run. If you actually want to run it against the whole URL, then there's no point in doing it more than once. But since the exclude feature is there to remove parts of the URL, this doesn't sound right to me.

    Also, I noticed that there doesn't seem to be a test case for the exclude feature.

  • πŸ‡©πŸ‡ͺGermany spuky

    I would guess you where counting on a bug with the field

    now the behavior is..
    below an entered path there are no more segments generated (including the page title)

    kat1
    --kat1-1
    ----kat1-1-1
    ------kat1-1-1-1
    --kat1-2
    ----kat-1-2-1

    having that

    i can use kat1\/kat1-1\/kat1-1-1

    to hide everything below the path from the breadcrumb.

    I was not involved in the bugfix for the feature... ( Just happend to roll the release where the change was included)
    but from reading the description of excluding paths.. i would have guessed that what it does...excluding paths not segments..

    so putting /node in there hides elements for everything below /node wich describes your behavior...

    I see your use case... though

    And there is a solution with using:

    Paths to replace with custom breadcrumbs

    regex!/node/([0-9]*)::

    this is not easy to discover unless you know your way around that feature but should give you a first working solution

    so my Suggestion would be:

    We close this issue as Works as designed...
    and open a Feature Request to make an easy Option to Skip Segments

    And yes you are right we are missing lots of test cases (feel free to provide MRs with additional tests )

  • πŸ‡©πŸ‡ͺGermany spuky
    Paths to replace with custom breadcrumbs

    regex!/node/([0-9]*)::

    No that does not help... since it is matching on both url alias and internal path... looked good on first try... but...when checking another node with an alias it also matched..

  • πŸ‡©πŸ‡ͺGermany spuky

    Ok figured it out you must set both:

    Paths to be excluded while generating segments:
    \/node\/

    Paths to replace with custom breadcrumbs:
    regex!/node/([0-9]*/)::

  • πŸ‡·πŸ‡΄Romania bbu23

    Indeed, I have the same issue. I updated the module from 2.0.5 to 2.0.8, and now the existing breadcrumbs are not being displayed at all anymore.

  • πŸ‡©πŸ‡ͺGermany spuky

    could you share a little more about what breadcrumbs are not there with which config... ?

  • πŸ‡·πŸ‡΄Romania bbu23

    I will have to gather more info, that was what I observed immediately after the update. Though on my multisite, one of the breadcrumbs were showing. So, I will check why the other doesn't and when I have more info I'll get back here.

  • πŸ‡ΊπŸ‡ΈUnited States attheshow

    We had some dynamically built pages (not nodes or entities, but with the body of the page being built on the fly via external API calls) that had aliases like /catalog/. Those previously had breadcrumbs like Catalog > 1234 being shown in version 2.0.7 but those are no longer appearing in 2.0.8.

  • πŸ‡©πŸ‡ͺGermany spuky

    @atteshow.. could you share more about your config.. any exclusions set ?

  • πŸ‡ΊπŸ‡ΈUnited States attheshow

    @spuky It doesn't look like we have any exclusions set in the config (https://gist.github.com/attheshow/4cbb070ed15cd1c955c6f0158ad8f87b). I'm trying to think of what else might cause the issue... I wonder if it could be something in our existing implementation of hook_preprocess_breadcrumb() that's not playing nicely with the latest code.

  • πŸ‡·πŸ‡΄Romania bbu23

    @spuky here's the exact problem that I have:

    - I'm using exclude paths
    - The only value present is one path. E.g. something
    - The page that I am visiting is: /something/should/not/be/included
    - The breadcrumb doesn't show

    After investigation, here's what I got:

    File web/modules/contrib/easy_breadcrumb/src/EasyBreadcrumbBuilder.php (going to reference the exact lines from here https://git.drupalcode.org/project/easy_breadcrumb/-/blob/2.x/src/EasyBr...)

    line 504: Adds the language (will matter later)
    line 531: The most problematic one, basically this one will always return true for my case. While each sets of paths are being checked, "something" is always present and the regex check from line 527 is always true, therefore all paths are being excluded, whereas I want only the first part (something) to be excluded.
    BUT, if I remove the regex completely to use the exact match instead (since I don't need it and just to check) here comes line 504, which by the time it gets to "/something", it will be 'something' == '/en/something'

    Regex is not really a good idea for this type of scenario. Or maybe improved, or allow us to en/dis regex, or idk. And the exact match should not use the language, it always fails.

    I hope this helps.

  • πŸ‡·πŸ‡΄Romania bbu23

    I created a local custom patch for my particular case, not sharing it here because it's not general and definitely impacts others. I'm just sharing what I changed for informational purposes:

    1. Removed the use of $add_langcode

    2. Removed the langcode and slash from the $check_path
    Before:

    $check_path = '/' . implode('/', $path_elements);
    if ($add_langcode) {
      $check_path = '/' . $curr_lang . $check_path;
    }
    

    After:

    $check_path = implode('/', $path_elements);
    

    3. Completely removed regex
    The following code removed:

    $regex_match_found = FALSE;
    $exclude_is_regex = !@preg_match($escaped_exclude_segment, NULL);
    
    // Check path against exclude segment.
    if ($exclude_is_regex === TRUE) {
      $regex_match_found = preg_match('/' . $escaped_exclude_segment . '/', $check_path, $matches);
    }
    

    and this bit replaced:
    before:

    if ($regex_match_found || $escaped_exclude_segment == $check_path) {
    

    after:

    if ($escaped_exclude_segment == $check_path) {
    
  • πŸ‡©πŸ‡ͺGermany ammaletu Bonn, Germany

    @spuky (see #6): I think I got this to work now. I did not use "Paths to be excluded while generating segments". As soon as that contains "node", no breadcrumbs are generated anymore, because there is nothing in front of "node" to generate a segment.

    Instead, I used "Paths to replace with custom breadcrumbs" with:
    regex!/node/([0-9]*) :: <title>

    That seems to do the trick.

    Another question is, why this is even necessary for nodes? This works out of the box for groups (/de/group/123) and for users (/user/42). They each get a breadcrumb like "Startpage > Unlinked Title". Only nodes get "Startpage > > Unlinked Title". So maybe the real bug is this empty segment for nodes?

  • πŸ‡¬πŸ‡§United Kingdom gsquirrel London

    I am also experiencing this issue

    Previously it worked fine to exclude just one segment of the url (which did not correspond to a page). Now if I have that in the exclude section I get no breadcrumbs at all.

    This is since the update to latest version.

    My use case - I have a pages with urls like this: /toolkit/getting-started/normative-frameworks-cse

    I want the Getting Started section breadcrumb, I want the current page title in the breadcrumb, but there is no page at /toolkit so I want to exclude that segment of the url.

    How do you do this in the new version? I tried your code above and that did not help

Production build 0.71.5 2024