EntityTypeBundleInfo returns wrong language

Created on 8 May 2024, 9 months ago

Problem/Motivation

EntityTypeBundleInfo returns wrong language version when called before language negotiation is finished.

Turns out it still has a static cache property (not aware of cache contexts like language or cache tag invalidation).

Steps to reproduce

After quire some debugging it boils down to this minimal test-code:
- Set current interface language to en
- Call EntityTypeBundleInfo::getAllBundleInfo
- Set current interface language to de
- Call EntityTypeBundleInfo::getAllBundleInfo
- Expected: Get de translation.
- Actual: Get en translation.

This happened on my installation in this scenario:
- Have an entity (commerce_store) with some paragraph fields
- `drush cr`
- Create (not edit) commerce store (in my case in group context)
- Expected: See Paragraph button "[DE bundle label] hinzufügen"
- Actual: See Paragraph button "[EN bundle label] hinzufügen"
- FTR: Also, clicking that paragraph button adds a *different* paragraph (that with the last button) to the form. (Which looks like a separate form builder bug.)

Proposed resolution

Replace static cache with memory cache backend (like everywhere else).

Remaining tasks

- Code, review, commit.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Entity 

Last updated 1 day ago

Created by

🇩🇪Germany geek-merlin Freiburg, Germany

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

Merge Requests

Comments & Activities

  • Issue created by @geek-merlin
  • Status changed to Needs work 9 months ago
  • 🇩🇪Germany geek-merlin Freiburg, Germany

    Added MR with one commit that adds a language key to the static cache.

    It fixes the issue for me and proves that this low-level approach fixes the described behavioral issue.

    The proper fix is of course a memory cache backend that handles invalidation too.

  • Pipeline finished with Success
    9 months ago
    Total: 609s
    #167716
  • First commit to issue fork.
  • 🇸🇪Sweden maxsjoblom Örnsköldsvik

    We found a case where the English translations got cached under a different langcode, because config translation overrides weren't loaded yet by the event listener \Drupal\language\EventSubscriber\LanguageRequestSubscriber::setLanguageOverrides . Since the entity bundle info translations are based on the config override system, we first try to use the active config override language and then fall back to current language. This makes sure that the cached values matches the cache key.

  • 🇸🇪Sweden twod Sweden

    I'll take a look at fixing the test mocks in a bit.

Production build 0.71.5 2024