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
Loading
Loading
Loading
Loading
+8 −0
Changes for core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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'];
    }
+13 −0
Changes for core/modules/config/tests/config_schema_deprecated_test/config/schema/config_schema_deprecated_test.schema.yml: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
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
+5 −0
Changes for core/modules/config/tests/config_schema_deprecated_test/config_schema_deprecated_test.info.yml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
name: 'Deprecated configuration schema test'
type: module
package: Testing
version: VERSION
hidden: true
+36 −0
Changes for core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaDeprecationTest.php: 36 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?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'));
  }

}