Problem/Motivation

Admin Toolbar Search gets some of its suggestions from the server (SearchLinks::getLinks()): the bundles and menus beyond max_bundle_number, which are not in the toolbar menu. These suggestions are cached by interface language and user permissions, and the labels follow the interface language.

However, after editing only the translation of a label (for example the Spanish label of a content type or a menu), the suggestion of this language keeps the old text, until the cache is invalidated for another reason. Editing the English label is refreshed correctly.

The cached links are tagged with config:core.extension, the list cache tags of the bundle entity types and config:menu_list, which are not invalidated when a language override is saved. The cache tags of each bundle and each menu used for the labels are missing.

Initially reported in: #3629740-8: Views and module dropdown labels remain English across interface languages

Steps to reproduce

  1. Enable Admin Toolbar, Admin Toolbar Tools and Admin Toolbar Search, Language and Configuration Translation, and add a second language, for example Spanish.
  2. Set max_bundle_number in the Admin Toolbar Tools settings to a low value (for example 1) and create at least two content types, so the last one is only found by the search suggestions.
  3. As a user with access to the search, type the label of this content type in the search field in each language, so the suggestions are cached.
  4. Edit only the Spanish translation of the label of this content type.
  5. Search for it again in Spanish: the suggestion still shows the old label. After editing the English label, the English suggestion is updated.

Proposed resolution

Add the cache tags of each bundle and each menu used in the labels (getCacheTags() of the entity) to the cache tags of the links in SearchLinks::getLinks(), where the labels of the bundles and the menus are built, in addition to the current list tags. This was suggested in comment #8 of #3629740 and has not been implemented or tested yet.

Remaining tasks

  • Write a test reproducing the stale suggestion after a translation-only edit (Kernel or Functional test, calling SearchLinks::getLinks() or the search route).
  • Add the cache tags and check the test passes.
  • Review.

User interface changes

None. The search suggestions are updated after a translation of a label changes.

API changes

None.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dydave created an issue. See original summary.

stingo-36 made their first commit to this issue’s fork.

stingo-36’s picture

Status: Active » Needs review
ressa’s picture

Thanks, I wonder if AI was used? Policy on the use of AI when contributing to Drupal.

stingo-36’s picture

Yes, I used an AI assistant (Claude) to help investigate the bug, write the fix and the Kernel test.
Sorry for not disclosing that in the MR.

I verified the result myself before submitting:
- The new Kernel test fails on 3.x without the fix and passes with it.
- I reproduced the bug manually on a Drupal 11.4 site with Spanish and max_bundle_number set to 1: /es/admin/admin-toolbar-search kept the old Spanish labels after a translation-only edit, and returned the new labels with the fix.

I'll add an AI disclosure note to the MR description.
Happy to make any changes

csakiistvan’s picture

Assigned: Unassigned » csakiistvan
csakiistvan’s picture

Assigned: csakiistvan » Unassigned
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new260.53 KB
new350.98 KB
new299.85 KB

✅ Tested and works — before the fix, with max_bundle_number set to 1, editing only the French label of a content type left the stale label in the "Content type > … > Edit/Manage fields/…" search suggestions on /fr/admin. After applying MR !229 and rebuilding caches, a second French-only label edit showed up in those suggestions straight away. The MR's new kernel test passes with the fix and fails without it (Failed asserting that an array contains 'Content type > Tipo zulu editado > Edit'), so the missing bundle cache tags are covered.

dydave’s picture

Thanks everyone! 🙏

The changes look good! I fixed small errors with the cspell and phpstan jobs.

We should be able to get this merged and included in the next release 3.7.0. 👌

  • dydave committed 5fcc88b5 on 3.x authored by stingo-36
    Issue #3635997 by stingo-36, csakiistvan, dydave: Added the bundle and...
dydave’s picture

Status: Reviewed & tested by the community » Fixed

Merged, thanks everyone! 🙏

The search links that Admin Toolbar Search gets from the server (SearchLinks::getLinks()) are now also tagged with the cache tags of each bundle and each menu used in the labels (for example config:node.type.article or config:system.menu.footer), in addition to the existing list tags. Saving only a translation (a language configuration override) of a label now invalidates the cached suggestions of that language, so they are refreshed immediately.

A new Kernel test, AdminToolbarSearchTranslatedLabelsTest, caches the links in Spanish, edits only the Spanish labels of a content type and a menu, and checks the new labels are returned. It fails without the fix and passes with it.

Thanks to @stingo-36 for the MR, to @csakiistvan for reviewing and testing it, and to @ressa for the review comments.

The fix will be included in the next release. 🥳

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.