Drupal\language\EventSubscriber\ConfigSubscriber::onConfigSave can create strange language prefix configuration

Created on 4 August 2022, over 2 years ago
Updated 17 February 2023, about 2 years ago

Problem/Motivation

I have a site that was installed. Then I went ahead and changed its site name. This in turn updated the language config, so the diff looks like so:

--- a/config/common/language.negotiation.yml
+++ b/config/common/language.negotiation.yml
@@ -6,6 +6,7 @@ url:
   prefixes:
     en: en
     nb: ''
+    '': null

This is because the following logic:

if ($saved_config->getName() == 'system.site' && $event->isChanged('default_langcode')) {

Well, the saved config was indeed system.site. But the default_langcode was not changed. Only the system.site.name config was changed. So why is it that $event->isChanged('default_langcode') returns true? Well it's because the $config->original is not equal to the $config->data. Because $config->original is empty, since that is initialized after the config object creates this event (from Config.php):

    $this->eventDispatcher->dispatch(new ConfigCrudEvent($this), ConfigEvents::SAVE);
    $this->originalData = $this->data;

This is not true if you change the config through the site information config form. But if you import a config change for system.site, naturally a save event for the config will happen, and then $config->original will be empty. It should be possible to write a test for this, but I have at least confirmed it with a clean install on 9.5.x.

Steps to reproduce

  • Install Drupal
  • Enable language module
  • Export the config
  • Edit the site name yml file, for example just the name
  • Import the config (i used drush)
  • Now export the config again (expecting it to be no changes). There is a change in language negotiation

Proposed resolution

Check that there is original config? Or just check that the old default language is not falsy?

Remaining tasks

Decide on an approach. Write tests

User interface changes

none

API changes

none

Data model changes

none

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
Language systemΒ  β†’

Last updated 7 days ago

  • Maintained by
  • πŸ‡©πŸ‡ͺGermany @sun
Created by

πŸ‡³πŸ‡΄Norway eiriksm Norway

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    As a bug this needs a test case

    In the issue summary the proposed solution seems like a question, is that the solution that was taken?

Production build 0.71.5 2024