Replaced breadcrumb title is reset when an alternative title field name is configured

Created on 16 April 2024, 12 months ago
Updated 24 August 2024, 8 months ago

After upgrading from 2.0.5 to 2.0.6 I've discovered what seems to be a bug introduced by #2931141 ✨ Breadcrumb based on an alternative field Fixed . Basically, if I have defined some replacement titles in the "Titles to be replaced while generating segments" field, the modified/replaced title strings in some situations* are being reset back to their original value whenever there is also a value in the "Alternative title field name" field (and since the module provides a default value for that field when it is installed there's likely going to be a value there whether or not the user is actually intending to use an alternate field.)

* This behavior is happening when we have a view that uses Twig code in its title field such as {{ Drupal_field('label', 'group', Raw_arguments.field_display_in_group, {label: 'hidden'}) }} to display a dynamic title based on a group name. To prevent that raw code from appearing in breadcrumb titles, we've added a replacement value like {{ Drupal_field('label', 'group', Raw_arguments.field_display_in_group, {label: 'hidden'}) }} Events::Events. This title replacement worked fine in 2.0.5, but doesn't work in 2.0.6 when an alternate title field name is also specified.

I don't understand how the code added to EasyBreadcrumbBuilder.php by #2931141 ✨ Breadcrumb based on an alternative field Fixed is supposed to work because I don't see where it actually retrieves the alternate field title. It just seems to retrieve the original title again and then overwrites the replaced title value with the original title value:

Assuming this alternative title field code does actually work if you're using an alternative title field, shouldn't it also run the title replacement logic on that field's title value?

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States RichardDavies Portland, Oregon

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

Merge Requests

Comments & Activities

  • Issue created by @RichardDavies
  • πŸ‡ΊπŸ‡ΈUnited States RichardDavies Portland, Oregon
  • First commit to issue fork.
  • Pipeline finished with Failed
    10 months ago
    Total: 175s
    #198082
  • πŸ‡©πŸ‡ͺGermany spuky

    I don't understand how the code added to EasyBreadcrumbBuilder.php by #2931141 is supposed to work because I don't see where it actually retrieves the alternate field title. It just seems to retrieve the original title again and then overwrites the replaced title value with the original title value:

    The fetching of the Alternative Title field is done in the getTitle method of the TitleResolver Class

    it would already fetch the replacement title there ... but the fetching you marked with 1. is only done if you also have "Use Page title when available" set to true.

    I submitted code that would also do the Replacement for the "alternative title field". So you could use the diff as a patch for the Situation

    It could be up for discussion if this replacement code for the alternative title needed.. Since if you have a dedicated field for your breadcrumb Title you could change it there without the need to change your Page Title / Menu title...

    ...unless the Field you use as alternative title is also a multipurpose field in your architecture..

    I can understand your expectation of replacement so it might be a better UX to do the replacement in both cases

    Or

    make it clearer that the replacement does not apply to alternate_title_fields but only to fallback Menutitles and Pagetitles.. but not for "alternative title fields"

  • πŸ‡©πŸ‡ͺGermany spuky

    Ok I reasoned about that a little more since the default config provides an fieldname (and even if the fieldname does not exist this codepath is taken... )

    Option1:
    have the replacement code as in my commit (we might move it after all Options to have only one place where replacements happen..)

    Option2:
    come with empty "Alternative title field name" and provide the example in the field description...
    Maybe check for existence of field on saving the config form...
    Have an update function that clears the "Alternative title field name" if the field does not exist..
    but even that would get Arround the replacement for users that have the "Alternative title field" on some entity types but not all...

  • Pipeline finished with Failed
    10 months ago
    Total: 145s
    #198220
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    6 pass
  • Status changed to Needs review 10 months ago
  • πŸ‡©πŸ‡ͺGermany spuky

    The merge request implements option 1 would like to write tests for that... but I don't know when i get to that so we could merge this as a Bug fix.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 8
    last update 9 months ago
    7 pass
  • πŸ‡©πŸ‡ͺGermany spuky

    from the description it seems 3220847 is a duplicate of this... issue...

  • Pipeline finished with Skipped
    8 months ago
    #245506
  • Status changed to Fixed 8 months ago
    • spuky β†’ committed d89133e4 on 2.x
      Issue #3441176 by spuky, RichardDavies: Replaced breadcrumb title is...
  • πŸ‡©πŸ‡ͺGermany spuky
    • spuky β†’ committed d89133e4 on feature/megre_dynamic-breadcrumbs
      Issue #3441176 by spuky, RichardDavies: Replaced breadcrumb title is...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024