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
- Enable Admin Toolbar, Admin Toolbar Tools and Admin Toolbar Search, Language and Configuration Translation, and add a second language, for example Spanish.
- Set
max_bundle_numberin 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. - 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.
- Edit only the Spanish translation of the label of this content type.
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3635997 after, new.png | 299.85 KB | csakiistvan |
| #8 | 3635997 after.png | 350.98 KB | csakiistvan |
| #8 | 3635997 before.png | 260.53 KB | csakiistvan |
Issue fork admin_toolbar-3635997
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
Comment #4
stingo-36 commentedComment #5
ressaThanks, I wonder if AI was used? Policy on the use of AI when contributing to Drupal.
Comment #6
stingo-36 commentedYes, 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
Comment #7
csakiistvanComment #8
csakiistvan✅ Tested and works — before the fix, with
max_bundle_numberset 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.Comment #9
dydave commentedThanks 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. 👌
Comment #11
dydave commentedMerged, 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 exampleconfig:node.type.articleorconfig: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. 🥳