diff --git a/core/modules/serialization/serialization.services.yml b/core/modules/serialization/serialization.services.yml index 89a9261e20..444358aef9 100644 --- a/core/modules/serialization/serialization.services.yml +++ b/core/modules/serialization/serialization.services.yml @@ -20,7 +20,7 @@ services: serializer.normalizer.primitive_data: class: Drupal\serialization\Normalizer\PrimitiveDataNormalizer tags: - - { name: normalizer, priority: 5 } + - { name: normalizer, priority: 5, bc: bc_primitives_as_strings, bc_config_name: 'serialization.settings' } serializer.normalizer.complex_data: class: Drupal\serialization\Normalizer\ComplexDataNormalizer tags: diff --git a/core/modules/serialization/src/RegisterSerializationClassesCompilerPass.php b/core/modules/serialization/src/RegisterSerializationClassesCompilerPass.php index 7be63fea97..7110056f60 100644 --- a/core/modules/serialization/src/RegisterSerializationClassesCompilerPass.php +++ b/core/modules/serialization/src/RegisterSerializationClassesCompilerPass.php @@ -23,7 +23,9 @@ public function process(ContainerBuilder $container) { // Retrieve registered Normalizers and Encoders from the container. foreach ($container->findTaggedServiceIds('normalizer') as $id => $attributes) { - if ($this->normalizerShouldBeSkipped($id)) { + // If there is a BC key present, pass this to determine if the normalizer + // should be skipped. + if (isset($attributes[0]['bc']) && $this->normalizerBcSettingIsEnabled($attributes[0]['bc'], $attributes[0]['bc_config_name'])) { continue; } @@ -59,32 +61,14 @@ public function process(ContainerBuilder $container) { } /** - * Determines whether a given normalizer should be skipped and not added. - * - * @param string $id - * The normalizer ID. - * - * @return bool - */ - protected function normalizerShouldBeSkipped($id) { - switch ($id) { - case 'serializer.normalizer.primitive_data': - return $this->normalizerBcSettingIsEnabled('bc_primitives_as_strings'); - default: - // Default to FALSE as most normalizers will be added. - return FALSE; - } - } - - /** * Returns whether a normalizer BC setting is disabled or not. * * @param string $key * * @return bool */ - protected function normalizerBcSettingIsEnabled($key) { - $settings = BootstrapConfigStorageFactory::get()->read('serialization.settings'); + protected function normalizerBcSettingIsEnabled($key, $config_name) { + $settings = BootstrapConfigStorageFactory::get()->read($config_name); return !empty($settings[$key]); }