diff --git a/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php b/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php index 80045d030367afc05ed8c8f469e17cc9faf22867..4e044f96726f4808d53ad6e5e5cc419757368dc0 100644 --- a/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php +++ b/core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php @@ -79,7 +79,15 @@ public function checkConfigSchema(TypedConfigManagerInterface $typed_config, $co */ protected function checkValue($key, $value) { $error_key = $this->configName . ':' . $key; + /** @var \Drupal\Core\TypedData\TypedDataInterface $element */ $element = $this->schema->get($key); + + // Check if this type has been deprecated. + $data_definition = $element->getDataDefinition(); + if (!empty($data_definition['deprecated'])) { + @trigger_error($data_definition['deprecated'], E_USER_DEPRECATED); + } + if ($element instanceof Undefined) { return [$error_key => 'missing schema']; } diff --git a/core/modules/config/tests/config_schema_deprecated_test/config/schema/config_schema_deprecated_test.schema.yml b/core/modules/config/tests/config_schema_deprecated_test/config/schema/config_schema_deprecated_test.schema.yml new file mode 100644 index 0000000000000000000000000000000000000000..40359e418c489c46b7a85e29ca71a58d52406538 --- /dev/null +++ b/core/modules/config/tests/config_schema_deprecated_test/config/schema/config_schema_deprecated_test.schema.yml @@ -0,0 +1,13 @@ +config_schema_deprecated_test.settings: + type: config_object + mapping: + complex_structure_deprecated: + type: mapping + deprecated: "The 'complex_structure_deprecated' config schema is deprecated in drupal:9.1.0 and is removed from drupal 10.0.0. Use the 'complex_structure' config schema instead. See http://drupal.org/node/the-change-notice-nid." + mapping: + type: + type: string + products: + type: sequence + sequence: + type: string diff --git a/core/modules/config/tests/config_schema_deprecated_test/config_schema_deprecated_test.info.yml b/core/modules/config/tests/config_schema_deprecated_test/config_schema_deprecated_test.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..c511c61ef374cc93e0a91377de01965d6b70ba2e --- /dev/null +++ b/core/modules/config/tests/config_schema_deprecated_test/config_schema_deprecated_test.info.yml @@ -0,0 +1,5 @@ +name: 'Deprecated configuration schema test' +type: module +package: Testing +version: VERSION +hidden: true diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaDeprecationTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaDeprecationTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d2ce47daf65bdeeafa6f0238ded5c5f10a7676d2 --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaDeprecationTest.php @@ -0,0 +1,36 @@ +<?php + +namespace Drupal\KernelTests\Core\Config; + +use Drupal\KernelTests\KernelTestBase; + +/** + * Tests config schema deprecation. + * + * @group config + * @group legacy + */ +class ConfigSchemaDeprecationTest extends KernelTestBase { + + /** + * {@inheritdoc} + */ + protected static $modules = [ + 'config_schema_deprecated_test', + ]; + + /** + * Tests config schema deprecation. + * + * @expectedDeprecation The 'complex_structure_deprecated' config schema is deprecated in drupal:9.1.0 and is removed from drupal 10.0.0. Use the 'complex_structure' config schema instead. See http://drupal.org/node/the-change-notice-nid. + */ + public function testConfigSchemaDeprecation() { + $config = $this->config('config_schema_deprecated_test.settings'); + $config + ->set('complex_structure_deprecated.type', 'fruits') + ->set('complex_structure_deprecated.products', ['apricot', 'apple']) + ->save(); + $this->assertSame(['type' => 'fruits', 'products' => ['apricot', 'apple']], $config->get('complex_structure_deprecated')); + } + +}