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 @@ -12,6 +12,7 @@ use Drupal\Core\Config\ConfigNameException; use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Config\TypedConfigManager; +use Drupal\Core\TypedData\PrimitiveInterface; /** * Defines the default configuration object. @@ -559,32 +560,21 @@ } if (is_scalar($value)) { try { - $class = get_class($this->getSchemaForKey($key)); + $element = $this->getSchemaForKey($key); + if ($element instanceof PrimitiveInterface) { + $value = $element->getCastedValue(); + } + else { + // Config only supports primitive data types. If the config schema + // does define a type $element will be an instance of + // \Drupal\Core\Config\Schema\Property. Convert it to string since it + // is the safest possible type. + $value = $element->getString(); + } } catch (\Exception $e) { // @todo throw an exception due to an incomplete schema. Only possible // once https://drupal.org/node/1910624 is complete. - $class = FALSE; - } - switch ($class) { - case 'Drupal\Core\TypedData\Plugin\DataType\String': - case 'Drupal\Core\TypedData\Plugin\DataType\Uri': - case 'Drupal\Core\TypedData\Plugin\DataType\Email': - case 'Drupal\Core\Config\Schema\Property': - $value = (string) $value; - break; - - case 'Drupal\Core\TypedData\Plugin\DataType\Integer': - $value = ($value !== '' ? (int) $value : NULL); - break; - - case 'Drupal\Core\TypedData\Plugin\DataType\Boolean': - $value = ($value !== '' ? (bool) $value : NULL); - break; - - case 'Drupal\Core\TypedData\Plugin\DataType\Float': - $value = ($value !== '' ? (float) $value : NULL); - break; } } else { diff -u b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php --- b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php @@ -257,7 +257,7 @@ 'integer' => '100', 'null_integer' => '', 'boolean' => 1, - // In the config schema this doesn't have a type so should cast to string. + // If the config schema doesn't have a type it should be casted to string. 'no_type' => 1, 'array' => array( 'string' => 1 only in patch2: unchanged: --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Binary.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Binary.php @@ -89,4 +89,11 @@ public function getString() { } return $contents; } + + /** + * @inheritdoc + */ + public function getCastedValue() { + return $this->getValue(); + } } only in patch2: unchanged: --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Boolean.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Boolean.php @@ -25,4 +25,10 @@ */ class Boolean extends PrimitiveBase implements BooleanInterface { + /** + * @inheritdoc + */ + public function getCastedValue() { + return ($this->value !== '' ? (bool) $this->value : NULL); + } } only in patch2: unchanged: --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Float.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Float.php @@ -25,4 +25,10 @@ */ class Float extends PrimitiveBase implements FloatInterface { + /** + * @inheritdoc + */ + public function getCastedValue() { + return ($this->value !== '' ? (float) $this->value : NULL); + } } only in patch2: unchanged: --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Integer.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Integer.php @@ -25,4 +25,10 @@ */ class Integer extends PrimitiveBase implements IntegerInterface { + /** + * @inheritdoc + */ + public function getCastedValue() { + return ($this->value !== '' ? (int) $this->value : NULL); + } } only in patch2: unchanged: --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/String.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/String.php @@ -25,4 +25,10 @@ */ class String extends PrimitiveBase implements StringInterface { + /** + * @inheritdoc + */ + public function getCastedValue() { + return (string) $this->value; + } } only in patch2: unchanged: --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Uri.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Uri.php @@ -23,6 +23,6 @@ * label = @Translation("URI") * ) */ -class Uri extends PrimitiveBase implements UriInterface { +class Uri extends String implements UriInterface { } only in patch2: unchanged: --- a/core/lib/Drupal/Core/TypedData/PrimitiveInterface.php +++ b/core/lib/Drupal/Core/TypedData/PrimitiveInterface.php @@ -28,4 +28,10 @@ public function getValue(); */ public function setValue($value); + /** + * Gets the primitive data value casted to the correct type. + * + * @return mixed + */ + public function getCastedValue(); }