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() {
  MediaType::load('remote_video')
    ->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 MediaType::load('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?

Comments

bgreco created an issue. See original summary.

bgreco’s picture

Issue summary: View changes
anybody’s picture

@bgreco do you execute the update in the browser (update.php) or using drush updb?

I agree, this is unexpected. Furthermore I already voted to make config English as fixed source language by design. That would make such things so much easier and clearer...

vijaycs85’s picture

quietone’s picture

Keep in mind that the Drupal Core issue queue is not the ideal place for support requests. The 'support request' option is there for filing support issues for contributed modules and themes. There are several support options listed on our Support page, including the Drupal Forums and Drupal Answers. There is also Drupal Slack. You may get better replies in one of those places.

quietone’s picture

Status: Active » Fixed

Came back to this and I read the other issue, #3568743: Convert / unify all default configs to the site default language. And there is also #3150540: Configuration langcode is forced to site default language. On first reading of those this is actually a bug.

I think the best direction here is to seek support/workarounds in other forums while those two issues are being solved. Or, of course, contributing on those issues. As I write this #3568743: Convert / unify all default configs to the site default language is at Needs Review, so that can be reviewed and tested.

I am closing this per the guidance in Handle or refer a support request in an issue.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.