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

  1. Install the Language module.
  2. Enable a module that replaces or decorates the language_manager service, and adds a language such as xx-test to getStandardLanguageList().
  3. Go to /admin/config/regional/language/add, select the new language and click "Add language".
  4. 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

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

tobyfu created an issue. See original summary.

tobyfu’s picture

Added patch.

tobyfu’s picture

removed now unused use statement

sleitner’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Can we get a failing test showing this problem.

yi_jiang’s picture

Refined this patch for Drupal ~11.3

yi_jiang changed the visibility of the branch 3367561-static-call-to to hidden.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

mehdi.najeddine made their first commit to this issue’s fork.

mehdi.najeddine’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs tests

Opened 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 the language_manager service. Its getStandardLanguageList() adds a language with the code xx-test. LanguageStandardListOverrideTest adds 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.