diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 52d91fd..fd6ba66 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -79,11 +79,30 @@ public function initWithData(array $data) { } /** - * {@inheritdoc} + * Gets data from this configuration object. + * + * @param string $key + * A string that maps to a key within the configuration data. + * For instance in the following configuration array: + * @code + * array( + * 'foo' => array( + * 'bar' => 'baz', + * ), + * ); + * @endcode + * A key of 'foo.bar' would return the string 'baz'. However, a key of 'foo' + * would return array('bar' => 'baz'). + * If no key is specified, then the entire data array is returned. + * @param bool $for_entity + * Add immutable information used for config entities. Defaults to FALSE. + * + * @return mixed + * The data that was requested. */ - public function get($key = '') { + public function get($key = '', $for_entity = FALSE) { if (!isset($this->overriddenData)) { - $this->setOverriddenData(); + $this->setOverriddenData($for_entity); } if (empty($key)) { return $this->overriddenData; @@ -149,17 +168,22 @@ public function setModuleOverride(array $data) { * provided by modules. Precedence or different module overrides is * determined by the priority of the config.factory.override tagged services. * + * @param bool $for_entity + * Add immutable information used for config entities. Defaults to FALSE. + * * @return \Drupal\Core\Config\Config * The configuration object. */ - protected function setOverriddenData() { + protected function setOverriddenData($for_entity = FALSE) { $this->overriddenData = $this->data; if (isset($this->moduleOverrides) && is_array($this->moduleOverrides)) { $this->overriddenData = NestedArray::mergeDeepArray(array($this->overriddenData, $this->moduleOverrides), TRUE); } if (isset($this->settingsOverrides) && is_array($this->settingsOverrides)) { $this->overriddenData = NestedArray::mergeDeepArray(array($this->overriddenData, $this->settingsOverrides), TRUE); - $this->overriddenData['isImmutable'] = TRUE; + if ($for_entity) { + $this->overriddenData['isImmutable'] = TRUE; + } } return $this; } @@ -273,11 +297,13 @@ public function getRawData() { * A string that maps to a key within the configuration data. * @param bool $apply_overrides * Apply any overrides to the original data. Defaults to TRUE. + * @param bool $for_entity + * Add immutable information used for config entities. Defaults to FALSE. * * @return mixed * The data that was requested. */ - public function getOriginal($key = '', $apply_overrides = TRUE) { + public function getOriginal($key = '', $apply_overrides = TRUE, $for_entity = FALSE) { $original_data = $this->originalData; if ($apply_overrides) { // Apply overrides. @@ -286,7 +312,9 @@ public function getOriginal($key = '', $apply_overrides = TRUE) { } if (isset($this->settingsOverrides) && is_array($this->settingsOverrides)) { $original_data = NestedArray::mergeDeepArray(array($original_data, $this->settingsOverrides), TRUE); - $original_data['isImmutable'] = TRUE; + if ($for_entity) { + $original_data['isImmutable'] = TRUE; + } } } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index 35e8b30..d96a035 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -183,8 +183,9 @@ protected function doLoadMultiple(array $ids = NULL) { $configs = []; $records = []; foreach ($this->configFactory->loadMultiple($names) as $config) { + $record = $this->overrideFree ? $config->getOriginal(NULL, FALSE, TRUE) : $config->get(NULL, TRUE); $id = $config->get($this->idKey); - $records[$id] = $this->overrideFree ? $config->getOriginal(NULL, FALSE) : $config->get(); + $records[$id] = $record; $configs[$id] = $config; } $entities = $this->mapFromStorageRecords($records, $configs); diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityOverrideTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityOverrideTest.php index 4a5e2dd..a5d3317 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityOverrideTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityOverrideTest.php @@ -83,12 +83,16 @@ function testConfEntityOverride() { self::assertSame($config_entity_data['weight'], $expected_original_data['weight']); // try saving override values + $thrown_exception = NULL; try { /** @var \Drupal\config_test\Entity\ConfigTest $config_entity */ $config_entity = $config_test_storage->load('dotted.default'); $config_entity->weight = 240; $config_entity->save(); - } catch (\Exception $e) {} + } catch (\Exception $e) { + $thrown_exception = $e; + } + self::assertNotNull($thrown_exception); // Verify that it contains the overridden data from $config. $config_entity = $config_test_storage->load('dotted.default');