Commit 0fb041fc authored by catch's avatar catch
Browse files

Issue #2997100 by claudiu.cristea, alexpott, penyaskito, tstoeckler, Pancho,...

Issue #2997100 by claudiu.cristea, alexpott, penyaskito, tstoeckler, Pancho, longwave, xjm: Introduce a way to deprecate config schemas
parent 4a8ea54d
......@@ -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'];
}
......
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
name: 'Deprecated configuration schema test'
type: module
package: Testing
version: VERSION
hidden: true
<?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'));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment