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.
string $context_name: The name of the config context service on the container or a fully qualified class implementing \Drupal\Core\Config\Context\ContextInterface.
\Drupal\Core\Config\Context\ContextInterface The configuration context object.
\Drupal\Core\Config\ConfigFactory
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;
}