diff --git a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php index c034ade..50b591d 100644 --- a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php +++ b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php @@ -90,11 +90,12 @@ public function normalize($entity, $format = NULL, array $context = array()) { // Ignore the entity ID and revision ID. $exclude = array($entity->getEntityType()->getKey('id'), $entity->getEntityType()->getKey('revision')); foreach ($fields as $field) { - $field_name = $field->getFieldDefinition()->getName(); + $definition = $field->getFieldDefinition(); + $field_name = $definition->getName(); if (in_array($field_name, $exclude)) { continue; } - if (($definition = $field->getFieldDefinition()) && $definition->getType() == 'password') { + if ($definition->getType() == 'password') { // Never normalize password items. continue; } diff --git a/core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php b/core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php index 154412b..07803ff 100644 --- a/core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php +++ b/core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php @@ -7,7 +7,7 @@ namespace Drupal\serialization\Normalizer; -use Symfony\Component\Serializer\Exception\RuntimeException; +use Drupal\Core\Field\FieldItemListInterface; /** * Converts the Drupal entity object structures to a normalized array. @@ -34,7 +34,7 @@ class ComplexDataNormalizer extends NormalizerBase { public function normalize($object, $format = NULL, array $context = array()) { $attributes = array(); foreach ($object as $name => $field) { - if (method_exists($field, 'getFieldDefinition') && ($definition = $field->getFieldDefinition()) && $definition->getType() == 'password') { + if ($field instanceof FieldItemListInterface && $field->getFieldDefinition()->getType() == 'password') { // Never normalize password items. continue; } diff --git a/core/modules/serialization/src/Tests/EntitySerializationTest.php b/core/modules/serialization/src/Tests/EntitySerializationTest.php index db0c944..9f2be3e 100644 --- a/core/modules/serialization/src/Tests/EntitySerializationTest.php +++ b/core/modules/serialization/src/Tests/EntitySerializationTest.php @@ -117,7 +117,7 @@ public function testNormalize() { ]); $account->save(); $normalized = $this->serializer->normalize($account); - $this->assertTrue(empty($normalized['pass'])); + $this->assertTrue(!array_key_exists('pass', $normalized)); } /**