function config_context_enter

Sets the config context on the config factory.

This allows configuration objects to be created using special configuration contexts eg. global override free or locale using a user preferred language. Calling this function affects all subsequent calls to config() until config_context_leave() is called.

Parameters

string $context_name: The name of the config context service on the container or a fully qualified class implementing \Drupal\Core\Config\Context\ContextInterface.

Return value

\Drupal\Core\Config\Context\ContextInterface The configuration context object.

See also

config_context_leave()

\Drupal\Core\Config\ConfigFactory

6 calls to config_context_enter()
ConfigLocaleOverride::testConfigLocaleOverride in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php
Tests basic locale override.
ConfigLocaleOverride::testConfigLocaleUserAndGlobalOverride in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php
Tests locale override in combination with global overrides.
ConfigLocaleOverride::testConfigLocaleUserOverride in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php
Tests locale override based on user's preferred language.
ConfigLocaleOverride::testInvalidContextName in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php
Tests config_context_enter() invalid context name handling.
ConfigOverrideTest::testConfOverride in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php
Tests configuration override.

... See full list

File

drupal/core/includes/config.inc, line 105
This is the API for configuration storage.

Code

function config_context_enter($context_name) {
  if (drupal_container()
    ->has($context_name)) {
    $context = drupal_container()
      ->get($context_name);
  }
  elseif (class_exists($context_name) && in_array('Drupal\\Core\\Config\\Context\\ContextInterface', class_implements($context_name))) {
    $context = drupal_container()
      ->get('config.context.factory')
      ->get($context_name);
  }
  else {
    throw new ConfigException(sprintf('Unknown config context service or class: %s', $context_name));
  }
  drupal_container()
    ->get('config.factory')
    ->enterContext($context);
  return $context;
}