diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php index e82b1ccd90..bd5fa99812 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManager.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php @@ -49,15 +49,15 @@ class TypedConfigManager extends TypedDataManager implements TypedConfigManagerI * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver - * The class resolver. + * (optional) The class resolver. */ - public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, CacheBackendInterface $cache, ModuleHandlerInterface $module_handler, ClassResolverInterface $class_resolver) { + public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, CacheBackendInterface $cache, ModuleHandlerInterface $module_handler, ClassResolverInterface $class_resolver = NULL) { $this->configStorage = $configStorage; $this->schemaStorage = $schemaStorage; $this->setCacheBackend($cache, 'typed_config_definitions'); $this->alterInfo('config_schema_info'); $this->moduleHandler = $module_handler; - $this->classResolver = $class_resolver; + $this->classResolver = $class_resolver ?: \Drupal::service('class_resolver'); } /** diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index 7f353be6e0..dbf0d5fec5 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -118,7 +118,10 @@ public function createDataDefinition($data_type) { } $class = $type_definition['definition_class']; $data_definition = $class::createFromDataType($data_type); - $data_definition->setTypedDataManager($this); + + if (method_exists($data_definition, 'setTypedDataManager')) { + $data_definition->setTypedDataManager($this); + } return $data_definition; } diff --git a/core/modules/config/tests/config_test/src/ConfigValidation.php b/core/modules/config/tests/config_test/src/ConfigValidation.php index 7bf5f70522..c8e04d88cc 100644 --- a/core/modules/config/tests/config_test/src/ConfigValidation.php +++ b/core/modules/config/tests/config_test/src/ConfigValidation.php @@ -18,7 +18,7 @@ class ConfigValidation { * The validation execution context. */ public static function validateLlama($object, ExecutionContextInterface $context) { - if ($object !== 'meh') { + if (in_array($object, ['llama', 'alpaca', 'guanaco', 'vicuña'], TRUE)) { $context->addViolation('no valid llama'); } } diff --git a/core/tests/Drupal/KernelTests/Config/TypedConfigTest.php b/core/tests/Drupal/KernelTests/Config/TypedConfigTest.php index ced7759647..d7b9ea2139 100644 --- a/core/tests/Drupal/KernelTests/Config/TypedConfigTest.php +++ b/core/tests/Drupal/KernelTests/Config/TypedConfigTest.php @@ -53,9 +53,10 @@ public function testTypedDataAPI() { $this->assertEquals('kitten', $mapping->get('type')->getValue()); $this->assertInstanceOf(IntegerInterface::class, $mapping->get('count')); $this->assertEquals(2, $mapping->get('count')->getValue()); + // Verify the item metadata is available. $this->assertInstanceOf(ComplexDataDefinitionInterface::class, $mapping->getDataDefinition()); - // @todo: Make metadata about contained properties available and add test - // coverage here. + $this->assertArrayHasKey('type', $mapping->getProperties()); + $this->assertArrayHasKey('count', $mapping->getProperties()); // Test accessing sequences. $sequence = $typed_config->get('giraffe');