Configuration updates on sites with English as a non-default language

Created on 24 March 2025, 3 months ago

Problem/Motivation

As a module author, I am having trouble writing a hook_update_N() function to rename the label of one of my config entities that works on sites where English is a non-default language.

Suppose my module provides a custom media type named "My media type", and I want to rename it to "Renamed media type" in a hook_update_N() function. According to Updating Configuration , I would expect to write my update function like this:

function mymodule_update_10000() {
  \Drupal::configFactory()
    ->getEditable('media.type.my_media_type')
    ->set('label', 'Renamed media type')
    ->save();
}

Expected result: the English config translation label gets changed to "Renamed media type". The Spanish config translation label does not change, because there's no Spanish translation for it in any .po file yet.

Actual result: The English config translation label remains "My media type". The Spanish config translation label is changed to "Renamed media type" (in English!).

Steps to reproduce

  1. Install Drupal in Spanish
  2. Add English as a second language
  3. Execute \Drupal::configFactory()->getEditable('media.type.remote_video')->set('label', 'Remote video updated')->save();
  4. Observe that the remote video label is now always in English

What is the appropriate way for module authors to update their configuration in such a way that it works on all sites, regardless of the default language?

💬 Support request
Status

Active

Version

10.5

Component

config_translation.module

Created by

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

Comments & Activities

Production build 0.71.5 2024