diff --git a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php index 008b56aea2..b8a5dafd12 100644 --- a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php +++ b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php @@ -5,7 +5,6 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\Plugin\DataType\EntityAdapter; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\hal\LinkManager\LinkManagerInterface; @@ -77,7 +76,7 @@ public function normalize($entity, $format = NULL, array $context = []) { ], ]; - $field_items = static::getNonInternalAccessibleProperties(EntityAdapter::createFromEntity($entity), $context); + $field_items = static::getNonInternalAccessibleProperties($entity->getTypedData(), $context); // If the fields to use were specified, only output those field values. if (isset($context['included_fields'])) { $field_items = array_filter($field_items, function (FieldItemListInterface $field_item) use ($context) { diff --git a/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php b/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php index b00f663c02..d17f3ece11 100644 --- a/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php +++ b/core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php @@ -2,8 +2,6 @@ namespace Drupal\serialization\Normalizer; -use Drupal\Core\Entity\Plugin\DataType\EntityAdapter; - /** * Normalizes/denormalizes Drupal content entities into an array structure. */ @@ -25,7 +23,7 @@ public function normalize($entity, $format = NULL, array $context = []) { ]; /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */ - return $this->normalizeProperties(EntityAdapter::createFromEntity($entity), $format, $context); + return $this->normalizeProperties($entity->getTypedData(), $format, $context); } } diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php index 4beecf420d..674943b0c9 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\serialization\Unit\Normalizer; +use Drupal\Core\TypedData\ComplexDataInterface; +use Drupal\Core\TypedData\DataDefinitionInterface; use Drupal\serialization\Normalizer\ContentEntityNormalizer; use Drupal\Tests\UnitTestCase; @@ -101,6 +103,7 @@ public function testNormalizeWithAccountContext() { $definitions = [ 'field_1' => $this->createMockFieldListItem(TRUE, $mock_account), 'field_2' => $this->createMockFieldListItem(FALSE, $mock_account), + // @todo Add test internal field. ]; $content_entity_mock = $this->createMockForContentEntity($definitions); @@ -121,11 +124,15 @@ public function testNormalizeWithAccountContext() { public function createMockForContentEntity($definitions) { $content_entity_mock = $this->getMockBuilder('Drupal\Core\Entity\ContentEntityBase') ->disableOriginalConstructor() - ->setMethods(['getFields']) + ->setMethods(['getTypedData']) ->getMockForAbstractClass(); - $content_entity_mock->expects($this->once()) - ->method('getFields') - ->will($this->returnValue($definitions)); + $typed_data = $this->prophesize(ComplexDataInterface::class); + $typed_data->getProperties(TRUE) + ->willReturn($definitions) + ->shouldBeCalled(); + $content_entity_mock->expects($this->any()) + ->method('getTypedData') + ->will($this->returnValue($typed_data->reveal())); return $content_entity_mock; } @@ -143,7 +150,15 @@ protected function createMockFieldListItem($access = TRUE, $user_context = NULL) ->method('access') ->with('view', $user_context) ->will($this->returnValue($access)); - + if ($access) { + $data_definition = $this->prophesize(DataDefinitionInterface::class); + $data_definition->isInternal() + ->willReturn(FALSE) + ->shouldBeCalled(); + $mock->expects($this->once()) + ->method('getDataDefinition') + ->will($this->returnValue($data_definition->reveal())); + } return $mock; }