diff --git a/core/modules/hal/src/Normalizer/FieldNormalizer.php b/core/modules/hal/src/Normalizer/FieldNormalizer.php index a4e175323ac1c38453609e1bf84a5c1a51edd144..167499a26f5ee9abfa351bad3c5902d18249ff13 100644 --- a/core/modules/hal/src/Normalizer/FieldNormalizer.php +++ b/core/modules/hal/src/Normalizer/FieldNormalizer.php @@ -11,9 +11,7 @@ class FieldNormalizer extends SerializationFieldNormalizer { /** - * The formats that the Normalizer can handle. - * - * @var array + * {@inheritdoc} */ protected $format = ['hal_json']; diff --git a/core/modules/hal/src/Normalizer/NormalizerBase.php b/core/modules/hal/src/Normalizer/NormalizerBase.php index 43a5a07161f5d3db4387b73289557898a0575f1e..8b18985b8b46adc40593e6958159693fc85cac2a 100644 --- a/core/modules/hal/src/Normalizer/NormalizerBase.php +++ b/core/modules/hal/src/Normalizer/NormalizerBase.php @@ -10,36 +10,22 @@ */ abstract class NormalizerBase extends SerializationNormalizerBase implements DenormalizerInterface { - /** - * The formats that the Normalizer can handle. - * - * @var array - */ - protected $formats = ['hal_json']; - /** * {@inheritdoc} */ - public function supportsNormalization($data, $format = NULL) { - return in_array($format, $this->formats) && parent::supportsNormalization($data, $format); - } + protected $format = ['hal_json']; /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = NULL) { - if (in_array($format, $this->formats) && (class_exists($this->supportedInterfaceOrClass) || interface_exists($this->supportedInterfaceOrClass))) { - $target = new \ReflectionClass($type); - $supported = new \ReflectionClass($this->supportedInterfaceOrClass); - if ($supported->isInterface()) { - return $target->implementsInterface($this->supportedInterfaceOrClass); - } - else { - return ($target->getName() == $this->supportedInterfaceOrClass || $target->isSubclassOf($this->supportedInterfaceOrClass)); - } + protected function checkFormat($format = NULL) { + if (isset($this->formats)) { + @trigger_error('::formats is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use ::$format instead. See https://www.drupal.org/node/2868275', E_USER_DEPRECATED); + + $this->format = $this->formats; } - return FALSE; + return parent::checkFormat($format); } } diff --git a/core/modules/serialization/src/Normalizer/NormalizerBase.php b/core/modules/serialization/src/Normalizer/NormalizerBase.php index 90d9b752581649e90c35e251f3fff3daf5bfa688..7916a9092af26cece73830911ea78eb806226045 100644 --- a/core/modules/serialization/src/Normalizer/NormalizerBase.php +++ b/core/modules/serialization/src/Normalizer/NormalizerBase.php @@ -17,6 +17,13 @@ abstract class NormalizerBase extends SerializerAwareNormalizer implements Norma */ protected $supportedInterfaceOrClass; + /** + * List of formats which supports (de-)normalization. + * + * @var string|string[] + */ + protected $format; + /** * {@inheritdoc} */ @@ -71,7 +78,7 @@ protected function checkFormat($format = NULL) { return TRUE; } - return in_array($format, (array) $this->format); + return in_array($format, (array) $this->format, TRUE); } }