Problem/Motivation
LanguageAddForm::copyFormValuesToEntity() gets the standard language list with a static call to LanguageManager::getStandardLanguageList(). The select list on the same form uses the language_manager service. A module can replace or decorate that service and add a language to getStandardLanguageList(). The new language then shows in the select list, but saving it fails, because the static call bypasses the service.
Steps to reproduce
- Install the Language module.
- Enable a module that replaces or decorates the
language_managerservice, and adds a language such asxx-testtogetStandardLanguageList(). - Go to /admin/config/regional/language/add, select the new language and click "Add language".
- A warning
Undefined array key "xx-test"is logged. The page shows "The website encountered an unexpected error." The language is not added.
Proposed resolution
Use the injected language manager: $this->languageManager->getStandardLanguageList() (patch in #3).
Remaining tasks
Review.
User interface changes
None.
API changes
None.
Data model changes
None.
AI usage
An LLM helped write the test and this summary. The steps were checked on main with the new functional test, which replaces the service class.
Issue fork drupal-3367561
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 #2
tobyfu commentedAdded patch.
Comment #3
tobyfu commentedremoved now unused use statement
Comment #4
sleitner commentedComment #5
smustgrave commentedCan we get a failing test showing this problem.
Comment #6
yi_jiang commentedRefined this patch for Drupal ~11.3
Comment #11
mehdi.najeddine commentedOpened MR !17868 against main with the change from patch #3. The fix commit keeps tobyfu as the author.
This adds the failing test asked for in #5. A new test module,
language_standard_list_test, replaces the class of thelanguage_managerservice. ItsgetStandardLanguageList()adds a language with the codexx-test.LanguageStandardListOverrideTestadds this language with the "Add language" button. Then it checks the status message, the label and the RTL direction.Without the fix, the test fails with
Warning: Undefined array key "xx-test". The page shows "The website encountered an unexpected error." The language is not saved. With the fix, the test passes.The issue summary now uses the bug template, with steps that match main.
Generated with the help of an LLM.