Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291122

Add new LanguageConfigContext to override language specific configuration

$
0
0

Sub-task of #1763640: Introduce config context to make original config and different overrides accessible

Problem/Motivation

Currently there is no direct way to access language specific configuration. One option is to create an user with specific language and end into user context with this new user, something like below:

    $account = entity_create('user', array(
      'name' => 'French user',
      'mail' => 'test@example.com',
      'created' => REQUEST_TIME,
      'status' => 1,
      'preferred_langcode' => 'fr',
    ));

    $user_config_context = config_context_enter('Drupal\user\UserConfigContext');
    $user_config_context->setAccount($account);

The problem with this approach is we can't create new user for every time we need to access config of another language. Good example is config_translation module which tried to load configuration of other languages in various site configuration pages.

Proposed solution

Introduce LanguageConfigContext so that the above code changed to:

    $language = language_load('fr');
    $user_config_context = config_context_enter('Drupal\language\LanguageConfigContext');
    $user_config_context->setLanguage($language);

References

Example of where this should be used: #2020347: Update config_translation_enter_context with User entity instead of context instead of creating User object


Viewing all articles
Browse latest Browse all 291122

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>