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 @@ -193,6 +193,7 @@ * Saves the configuration object. */ public function save() { + $this->validateData($this->data); $this->sortByKey($this->data); $this->storageDispatcher->selectStorage('write', $this->name)->write($this->name, $this->data); $this->isNew = FALSE; @@ -230,2 +231,34 @@ } + + /** + * Validates configuration data. + * + * @param array $data + * The configuration data to validate. + * + * @throws ConfigException + */ + public function validateData(array $data) { + array_walk_recursive($data, array('self', 'validateValue')); + } + + /** + * Validates a configuration value. + * + * Helper callback for array_walk_recursive(). + * + * @param mixed $value + * The configuration data value to validate. + * @param string $key + * The key of the value. + * + * @throws ConfigException + * + * @see Config::validateData() + */ + public function validateValue($value, $key) { + if (!is_scalar($value)) { + throw new ConfigException(sprintf('Unsupported non-scalar value of type %s in key %s in config object %s', gettype($value), $key, $this->name)); + } + } } reverted: --- b/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ a/core/lib/Drupal/Core/Config/DatabaseStorage.php @@ -13,7 +13,7 @@ /** * Defines the Database storage controller. */ +class DatabaseStorage implements StorageInterface { -class DatabaseStorage extends StorageBase { /** * Database connection options for this storage controller. @@ -77,7 +77,6 @@ * @todo Ignore slave targets for data manipulation operations. */ public function write($name, array $data) { - $this->validateData($name, $data); $data = $this->encode($data); $options = array('return' => Database::RETURN_AFFECTED) + $this->options; return (bool) $this->getConnection()->merge('config', $options) reverted: --- b/core/lib/Drupal/Core/Config/FileStorage.php +++ a/core/lib/Drupal/Core/Config/FileStorage.php @@ -12,7 +12,7 @@ /** * Defines the file storage controller. */ +class FileStorage implements StorageInterface { -class FileStorage extends StorageBase { /** * Configuration options for this storage controller. @@ -86,7 +86,6 @@ * @throws Drupal\Core\Config\StorageException */ public function write($name, array $data) { - $this->validateData($name, $data); $data = $this->encode($data); $status = @file_put_contents($this->getFilePath($name), $data); if ($status === FALSE) { reverted: --- b/core/lib/Drupal/Core/Config/NullStorage.php +++ a/core/lib/Drupal/Core/Config/NullStorage.php @@ -21,7 +21,7 @@ * * This also can be used for testing purposes. */ +class NullStorage implements StorageInterface { -class NullStorage extends StorageBase { /** * Implements Drupal\Core\Config\StorageInterface::__construct(). */ reverted: --- b/core/lib/Drupal/Core/Config/StorageBase.php +++ /dev/null @@ -1,35 +0,0 @@ - reverted: --- b/core/lib/Drupal/Core/Config/StorageInterface.php +++ a/core/lib/Drupal/Core/Config/StorageInterface.php @@ -89,36 +89,6 @@ public static function decode($raw); /** - * Validates configuration data. - * - * @param string $name - * The name of a configuration object to validate. - * @param array $data - * The configuration data to validate. - * - * @throws StorageException - */ - public function validateData($name, array $data); - - /** - * Validates a configuration value. - * - * Helper callback for array_walk_recursive(). - * - * @param mixed $value - * The configuration data value to validate. - * @param string $key - * The key of the value. - * @param string $name - * The name of the configuration object. - * - * @throws StorageException - * - * @see StorageBase::validateData() - */ - public function validateValue($value, $key, $name); - - /** * Gets configuration object names starting with a given prefix. * * Given the following configuration objects: diff -u b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php --- b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Config\DatabaseStorage; use Drupal\Core\Config\StorageException; +use Drupal\Core\Config\ConfigException; use Drupal\simpletest\WebTestBase; /** @@ -169,7 +170,7 @@ try { $config->save(); } - catch (StorageException $e) { + catch (ConfigException $e) { $message = $e->getMessage(); } $this->assertEqual($message, 'Unsupported non-scalar value of type resource in key invalid_type in config object config_test.invalid_data'); @@ -180,7 +181,7 @@ try { $config->setData($data)->save(); } - catch (StorageException $e) { + catch (ConfigException $e) { $message = $e->getMessage(); } $this->assertEqual($message, 'Unsupported non-scalar value of type object in key invalid_type in config object config_test.invalid_data'); diff -u b/core/modules/config/lib/Drupal/config/Tests/Storage/ConfigStorageTestBase.php b/core/modules/config/lib/Drupal/config/Tests/Storage/ConfigStorageTestBase.php --- b/core/modules/config/lib/Drupal/config/Tests/Storage/ConfigStorageTestBase.php +++ b/core/modules/config/lib/Drupal/config/Tests/Storage/ConfigStorageTestBase.php @@ -8,7 +8,6 @@ namespace Drupal\config\Tests\Storage; use Drupal\simpletest\WebTestBase; -use Drupal\Core\Config\StorageException; /** * Base class for testing storage controller operations. @@ -135,23 +134,6 @@ $this->assertIdentical($read_data, $data); } - /** - * Tests storage controller writing an invalid data type. - */ - function testInvalidData() { - $name = 'config_test.invalid_data'; - $data = array( - 'invalid_key' => new \stdClass(), - ); - try { - $data = $this->storage->write($name, $data); - } - catch (StorageException $e) { - $message = $e->getMessage(); - } - $this->assertEqual($message, sprintf('Unsupported non-scalar value of type object in key invalid_key in config object %s', $name)); - } - abstract protected function read($name); abstract protected function insert($name, $data);