diff -u b/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php --- b/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -50,14 +50,7 @@ protected $data; /** - * The overridden data of the configuration object. - * - * @var array - */ - protected $overrides = array(); - - /** - * The current runtime data ($data + $overrides). + * The current runtime data ($data + $overrides from Config Context). * * @var array */ @@ -275,10 +268,8 @@ * The configuration object. */ public function setOverride(array $data) { - if ($this->context->allowOverrides()) { - $this->overrides = NestedArray::mergeDeepArray(array($this->overrides, $data), TRUE); - $this->resetOverriddenData(); - } + $this->context->setOverrides($this->getName(), $data); + $this->resetOverriddenData(); return $this; } @@ -292,8 +283,9 @@ */ protected function setOverriddenData() { $this->overriddenData = $this->data; - if (!empty($this->overrides)) { - $this->overriddenData = NestedArray::mergeDeepArray(array($this->overriddenData, $this->overrides), TRUE); + $overrides = $this->context->getOverrides($this->getName()); + if (is_array($overrides)) { + $this->overriddenData = NestedArray::mergeDeepArray(array($this->overriddenData, $overrides), TRUE); } return $this; } diff -u b/core/lib/Drupal/Core/Config/Context/ConfigContext.php b/core/lib/Drupal/Core/Config/Context/ConfigContext.php --- b/core/lib/Drupal/Core/Config/Context/ConfigContext.php +++ b/core/lib/Drupal/Core/Config/Context/ConfigContext.php @@ -9,6 +9,7 @@ use Drupal\Core\Config\Config; use Drupal\Core\Config\ConfigEvent; +use Drupal\Component\Utility\NestedArray; use Drupal\Component\Uuid\Uuid; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -30,2 +31,9 @@ /** + * Any config overrides of key-value pairs. + * + * @var array + */ + protected $overrides = array(); + + /** * An event dispatcher instance to use for configuration events. @@ -42,13 +50,6 @@ protected $uuid; /** - * Allow overrides to apply in this context. - * - * @var bool - */ - protected $allowOverrides = TRUE; - - /** * Constructs the configuration context. * * @param \Symfony\Component\EventDispatcher\EventDispatcher $event_dispatcher @@ -105,10 +106,25 @@ } /** - * Implements \Drupal\Core\Config\Context\ContextInterface::allowOverrides(). + * Implements Drupal\Core\Config\Context\ContextInterface::setOverride(). + */ + public function setOverrides($config_name, $data) { + if (!isset($this->overrides[$config_name])) { + $this->overrides[$config_name] = $data; + } + else { + $this->overrides[$config_name] = NestedArray::mergeDeepArray(array($this->overrides[$config_name], $data), TRUE); + } + } + + /** + * Implements Drupal\Core\Config\Context\ContextInterface::getOverrides(). */ - public function allowOverrides() { - return $this->allowOverrides; + public function getOverrides($config_name) { + if (isset($this->overrides[$config_name])) { + return $this->overrides[$config_name]; + } + return FALSE; } } diff -u b/core/lib/Drupal/Core/Config/Context/ContextInterface.php b/core/lib/Drupal/Core/Config/Context/ContextInterface.php --- b/core/lib/Drupal/Core/Config/Context/ContextInterface.php +++ b/core/lib/Drupal/Core/Config/Context/ContextInterface.php @@ -79,10 +79,23 @@ /** - * Returns whether this context allows overrides. + * Sets the override data for a configuration object. * - * @return bool - * TRUE if overrides are allowed, FALSE otherwise. + * @param string $config_name + * Configuration name. + * @param array data + * The override data. */ - public function allowOverrides(); + public function setOverrides($config_name, $data); + + /** + * Gets the override data for a configuration object. + * + * @param string $config_name + * Configuration name. + * + * @return mixed + * The override data or FALSE if there is none. + */ + public function getOverrides($config_name); } diff -u b/core/lib/Drupal/Core/Config/Context/FreeConfigContext.php b/core/lib/Drupal/Core/Config/Context/FreeConfigContext.php --- b/core/lib/Drupal/Core/Config/Context/FreeConfigContext.php +++ b/core/lib/Drupal/Core/Config/Context/FreeConfigContext.php @@ -14,7 +14,17 @@ /** - * Overrides are not allowed in this context. + * Implements Drupal\Core\Config\Context\ContextInterface::getOverrides(). */ - protected $allowOverrides = FALSE; + public function getOverrides($config_name) { + // Do nothing as this is override free. + return FALSE; + } + + /** + * Implements Drupal\Core\Config\Context\ContextInterface::setOverride(). + */ + public function setOverrides($config_name, $data) { + // Do nothing as this is override free. + } }