diff --git a/core/lib/Drupal/Core/Config/Schema/Parser.php b/core/lib/Drupal/Core/Config/Schema/Parser.php deleted file mode 100644 index 9569244..0000000 --- a/core/lib/Drupal/Core/Config/Schema/Parser.php +++ /dev/null @@ -1,43 +0,0 @@ - 'any'); - } - else { - $definition += array('type' => 'str'); - } - } - // Create typed data object. - config_typed()->create($definition, $data, $name, $parent); - } - - /** - * Validate configuration data against schema data. - */ - static function validate($config_data, $schema_data) { - return self::parse($config_data, $schema_data)->validate(); - } - - static function getDefinition($type, $data) { - return config_definition($type); - } -} - diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php index c06ec51..2028d20 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManager.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php @@ -56,12 +56,12 @@ public function get($name) { */ public function create(array $definition, $value = NULL, $name = NULL, $parent = NULL) { if (!isset($definition['type'])) { - // Set default type 'str' if possible. If not it will be 'any'. + // Set default type 'string' if possible. If not it will be 'undefined'. if (is_string($value)) { - $definition['type'] = 'str'; + $definition['type'] = 'string'; } else { - $definition['type'] = 'any'; + $definition['type'] = 'undefined'; } } elseif (strpos($definition['type'], ']')) { diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php index 93a7b55..b72a54c 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php @@ -20,7 +20,7 @@ class ConfigSchemaTest extends DrupalUnitTestBase { * * @var array */ - public static $modules = array('system', 'locale', 'image'); + public static $modules = array('system', 'locale', 'image', 'config_test'); public static function getInfo() { return array( @@ -34,12 +34,48 @@ public function setUp() { parent::setUp(); config_install_default_config('module', 'system'); config_install_default_config('module', 'image'); + config_install_default_config('module', 'config_test'); } /** * Tests the basic metadata retrieval layer. */ function testSchemaMapping() { + // Nonexistent configuration key will have Unknown as metadata. + $definition = config_typed()->getDefinition('config_test.no_such_key'); + $expected = array(); + $expected['label'] = 'Unknown'; + $expected['class'] = '\Drupal\Core\Config\Schema\Property'; + $this->assertEqual($definition, $expected, 'Retrieved the right metadata for nonexistent configuration.'); + + // Configuration file without schema will return Unknown as well. + $definition = config_typed()->getDefinition('config_test.noschema'); + $this->assertEqual($definition, $expected, 'Retrieved the right metadata for configuration with no schema.'); + + // Configuration file with only some schema. + $definition = config_typed()->getDefinition('config_test.someschema'); + $expected = array(); + $expected['label'] = 'Schema test data'; + $expected['class'] = '\Drupal\Core\Config\Schema\Mapping'; + $expected['mapping']['testitem'] = array('label' => 'Test item'); + $expected['mapping']['testlist'] = array('label' => 'Test list'); + $this->assertEqual($definition, $expected, 'Retrieved the right metadata for configuration with only some schema.'); + + // Check type detection on elements with undefined types. + $config = config_typed()->get('config_test.someschema'); + $definition = $config['testitem']->getDefinition(); + $expected = array(); + $expected['label'] = 'Test item'; + $expected['class'] = '\Drupal\Core\TypedData\Type\String'; + $expected['type'] = 'string'; + $this->assertEqual($definition, $expected, 'Automatic type detection on string item worked.'); + $definition = $config['testlist']->getDefinition(); + $expected = array(); + $expected['label'] = 'Test list'; + $expected['class'] = '\Drupal\Core\Config\Schema\Property'; + $expected['type'] = 'undefined'; + $this->assertEqual($definition, $expected, 'Automatic type fallback on non-string item worked.'); + // Simple case, straight metadata. $definition = config_typed()->getDefinition('system.maintenance'); $expected = array(); diff --git a/core/modules/config/tests/config_test/config/config_test.noschema.yml b/core/modules/config/tests/config_test/config/config_test.noschema.yml new file mode 100644 index 0000000..3c9efe8 --- /dev/null +++ b/core/modules/config/tests/config_test/config/config_test.noschema.yml @@ -0,0 +1,4 @@ +testitem: "Whatever structure there is in this file" +testlist: + - "the main file has no schema, so individual items" + - "will not have any schema information." diff --git a/core/modules/config/tests/config_test/config/config_test.schema.yml b/core/modules/config/tests/config_test/config/config_test.schema.yml new file mode 100644 index 0000000..82028db --- /dev/null +++ b/core/modules/config/tests/config_test/config/config_test.schema.yml @@ -0,0 +1,8 @@ +config_test.someschema: + type: mapping + label: "Schema test data" + mapping: + "testitem": + label: "Test item" + "testlist": + label: "Test list" diff --git a/core/modules/config/tests/config_test/config/config_test.someschema.yml b/core/modules/config/tests/config_test/config/config_test.someschema.yml new file mode 100644 index 0000000..3afe100 --- /dev/null +++ b/core/modules/config/tests/config_test/config/config_test.someschema.yml @@ -0,0 +1,4 @@ +testitem: "Since this file at least has top level schema in config_test.schema.yml" +testlist: + - "Direct string items are identified and other items are" + - "recognized as undefined types." diff --git a/core/modules/contact/config/contact.schema.yml b/core/modules/contact/config/contact.schema.yml index f0b70bd..d9b4381 100644 --- a/core/modules/contact/config/contact.schema.yml +++ b/core/modules/contact/config/contact.schema.yml @@ -23,7 +23,6 @@ contact.settings: mapping: "default_category": type: string - required: yes "flood": type: mapping mapping: