Commit 497bec2d authored by Dries's avatar Dries
Browse files

Issue #1763640 by beejeebus, alexpott, YesCT, Jose Reyero, Gábor Hojtsy,...

Issue #1763640 by beejeebus, alexpott, YesCT, Jose Reyero, Gábor Hojtsy, das-peter, c31ck, heyrocker: Followup: Introduce config context to make original config and different overrides accessible.
parent 355c56eb
......@@ -105,7 +105,7 @@ function config($name) {
return drupal_container()->get('config.factory')->get($name);
}
/*
/**
* Sets the config context on the config factory.
*
* This allows configuration objects to be created using special configuration
......@@ -127,7 +127,7 @@ 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))) {
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);
......@@ -141,7 +141,7 @@ function config_context_enter($context_name) {
return $context;
}
/*
/**
* Leaves the current config context returning to the previous context.
*
* @see config_context_enter()
......@@ -410,7 +410,7 @@ function config_get_entity_type_by_name($name) {
return key($entities);
}
/*
/**
* Returns the typed config manager service.
*
* Use the typed data manager service for creating typed configuration objects.
......
......@@ -42,7 +42,7 @@ public function getConfig() {
}
/**
* Get configuration context object.
* Gets configuration context object.
*
* @return \Drupal\Core\Config\Context\ContextInterface
* Configuration context.
......
......@@ -93,7 +93,7 @@ public function get($name) {
*/
public function reset($name = NULL) {
if ($name) {
// Reinitialise the configuration object in all contexts.
// Reinitialize the configuration object in all contexts.
foreach ($this->getCacheKeys($name) as $cache_key) {
$this->cache[$cache_key]->init();
}
......@@ -162,13 +162,16 @@ public function getContext() {
* The config factory object.
*/
public function leaveContext() {
// Ensure at least one context is left on the stack. We already ensured
// there is at least one context set by taking the initial one in the
// constructor.
if (count($this->contextStack) > 1) {
array_pop($this->contextStack);
}
return $this;
}
/*
/**
* Gets the cache key for a given config name in a particular context.
*
* @param string $name
......
......@@ -60,7 +60,7 @@ public function __construct(EventDispatcher $event_dispatcher) {
}
/**
* Implements Drupal\Core\Config\Context\ContextInterface::init().
* Implements \Drupal\Core\Config\Context\ContextInterface::init().
*/
public function init() {
$this->setUuid();
......@@ -70,21 +70,21 @@ public function init() {
}
/**
* Implements Drupal\Core\Config\Context\ContextInterface::get().
* Implements \Drupal\Core\Config\Context\ContextInterface::get().
*/
public function get($key) {
return array_key_exists($key, $this->data) ? $this->data[$key] : NULL;
}
/**
* Implements Drupal\Core\Config\Context\ContextInterface::set().
* Implements \Drupal\Core\Config\Context\ContextInterface::set().
*/
public function set($key, $value) {
$this->data[$key] = $value;
}
/**
* Implements Drupal\Core\Config\Context\ContextInterface::setUuid().
* Implements \Drupal\Core\Config\Context\ContextInterface::setUuid().
*/
public function setUuid() {
$uuid = new Uuid();
......@@ -92,14 +92,14 @@ public function setUuid() {
}
/**
* Implements Drupal\Core\Config\Context\ContextInterface::getUuid().
* Implements \Drupal\Core\Config\Context\ContextInterface::getUuid().
*/
public function getUuid() {
return $this->uuid;
}
/**
* Implements Drupal\Core\Config\Context\ContextInterface::notify().
* Implements \Drupal\Core\Config\Context\ContextInterface::notify().
*/
public function notify($config_event_name, Config $config = NULL) {
$this->eventDispatcher->dispatch('config.' . $config_event_name, new ConfigEvent($this, $config));
......
......@@ -49,7 +49,7 @@ public function __construct(EventDispatcher $event_dispatcher) {
*/
public function get($class = NULL) {
if (!$class) {
$class = "Drupal\\Core\\Config\\Context\\ConfigContext";
$class = 'Drupal\Core\Config\Context\ConfigContext';
}
if (class_exists($class)) {
$context = new $class($this->eventDispatcher);
......
......@@ -23,7 +23,7 @@
interface ContextInterface {
/**
* Initialises a config context for use.
* Initializes a configuration context for use.
*
* @return \Drupal\Core\Config\Context\ConfigContext
* The config context object.
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of \Drupal\config\Tests\ConfigLocaleOverride.
* Contains \Drupal\config\Tests\ConfigLocaleOverride.
*/
namespace Drupal\config\Tests;
......@@ -112,8 +112,8 @@ function testConfigLocaleUserOverride() {
$config_factory = drupal_container()->get('config.factory');
$config_factory->enterContext($user_config_context->setAccount($account));
// Should not have to re-initialise config object to get new overrides as
// the new context will have a different uuid.
// Should not have to re-initialize the configuration object to get new
// overrides as the new context will have a different uuid.
$config = config('config_test.system');
$this->assertIdentical($config->get('foo'), 'de bar');
......
<?php
/**
* @file
* Definition of \Drupal\locale\LocaleConfigSubscriber.
* Contains \Drupal\locale\LocaleConfigSubscriber.
*/
namespace Drupal\locale;
......@@ -25,6 +25,7 @@
* $config is always a DrupalConfig object.
*/
class LocaleConfigSubscriber implements EventSubscriberInterface {
/**
* The language manager.
*
......@@ -32,15 +33,20 @@ class LocaleConfigSubscriber implements EventSubscriberInterface {
*/
protected $languageManager;
/**
* Default configuration context.
*
* @var \Drupal\Core\Config\Context\ContextInterface
*/
protected $defaultConfigContext;
/**
* Constructs a LocaleConfigSubscriber object.
*
* @param \Drupal\Core\Config\Context\ConfigContext $config_context
* The config context service.
* @param \Drupal\Core\Language\LanguageManager $language_manager
* The language manager service.
* @param \Drupal\Core\Config\Context\ConfigContext $config_context
* The configuration context service.
*/
public function __construct(LanguageManager $language_manager, ContextInterface $config_context) {
$this->languageManager = $language_manager;
......@@ -48,7 +54,7 @@ public function __construct(LanguageManager $language_manager, ContextInterface
}
/**
* Initialize configuration context with language.
* Initializes configuration context with language.
*
* @param \Drupal\Core\Config\ConfigEvent $event
* The Event to process.
......@@ -56,7 +62,9 @@ public function __construct(LanguageManager $language_manager, ContextInterface
public function configContext(ConfigEvent $event) {
$context = $event->getContext();
// Add user's language for user context.
// If there is a user set in the current context, set the language based on
// the preferred language of the user. Otherwise set it based on the
// negotiated interface language.
if ($account = $context->get('user.account')) {
$context->set('locale.language', language_load(user_preferred_langcode($account)));
}
......@@ -84,6 +92,12 @@ public function configLoad(ConfigEvent $event) {
}
}
/**
* Sets the negotiated interface language on the default configuration context.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* Kernel event to respond to.
*/
public function onKernelRequestSetDefaultConfigContextLocale(GetResponseEvent $event) {
if ($language = $this->languageManager->getLanguage(LANGUAGE_TYPE_INTERFACE)) {
$this->defaultConfigContext->set('locale.language', $language);
......@@ -102,7 +116,7 @@ public function onKernelRequestSetDefaultConfigContextLocale(GetResponseEvent $e
* The language object.
*
* @return string
* The localised config name.
* The localized config name.
*/
public function getLocaleConfigName($name, Language $language) {
return 'locale.config.' . $language->langcode . '.' . $name;
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\user\UserConfigContext
* Contains \Drupal\user\UserConfigContext.
*/
namespace Drupal\user;
......@@ -26,8 +26,8 @@ class UserConfigContext extends ConfigContext {
*/
const USER_KEY = 'user.account';
/*
* Helper function to create config context for user accounts.
/**
* Creates the configuration context for user accounts.
*
* @param \Drupal\user\Plugin\Core\Entity\User $account
* The account to add to the config context.
......
......@@ -1762,7 +1762,7 @@ function user_mail($key, &$message, $params) {
// this user is not necessarily the same as the one triggering the mail. This
// allows the configuration objects to be localized for the user's language if
// the locale module is enabled.
$user_config_context = config_context_enter("Drupal\\user\\UserConfigContext");
$user_config_context = config_context_enter('Drupal\user\UserConfigContext');
$user_config_context->setAccount($params['account']);
$mail_config = config('user.mail');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment