src/Normalizer/ConfigEntityNormalizer.php | 17 +++++++---------- .../JsonApiDocumentTopLevelNormalizerTest.php | 4 ++-- .../src/Unit/Normalizer/ConfigEntityNormalizerTest.php | 4 +--- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Normalizer/ConfigEntityNormalizer.php b/src/Normalizer/ConfigEntityNormalizer.php index 5d97676..3b8d06c 100644 --- a/src/Normalizer/ConfigEntityNormalizer.php +++ b/src/Normalizer/ConfigEntityNormalizer.php @@ -45,17 +45,14 @@ class ConfigEntityNormalizer extends EntityNormalizer { */ protected function serializeField($field, array $context, $format) { $output = $this->serializer->normalize($field, $format, $context); - if (is_array($output)) { - $output = new FieldNormalizerValue( - [new FieldItemNormalizerValue($output)], - 1 - ); - $output->setPropertyType('attributes'); - return $output; + if (!is_array($output)) { + $output = [$output]; } - $field instanceof Relationship ? - $output->setPropertyType('relationships') : - $output->setPropertyType('attributes'); + $output = new FieldNormalizerValue( + [new FieldItemNormalizerValue($output)], + 1 + ); + $output->setPropertyType('attributes'); return $output; } diff --git a/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php b/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php index 6d1afc9..4f494cf 100644 --- a/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php +++ b/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php @@ -264,7 +264,7 @@ class JsonApiDocumentTopLevelNormalizerTest extends JsonapiKernelTestBase { // Make sure that the cache tags for the includes and the requested entities // are bubbling as expected. $this->assertSame( - ['file:1', 'node:1', 'taxonomy_term:1', 'taxonomy_term:2'], + ['file:1', 'node:1', 'taxonomy_term:1', 'taxonomy_term:2', 'user:1'], $response->getCacheableMetadata()->getCacheTags() ); $this->assertSame( @@ -362,7 +362,7 @@ class JsonApiDocumentTopLevelNormalizerTest extends JsonapiKernelTestBase { // Make sure that the cache tags for the includes and the requested entities // are bubbling as expected. $this->assertSame( - ['node:1', 'taxonomy_term:1', 'taxonomy_term:2'], + ['node:1', 'taxonomy_term:1', 'taxonomy_term:2', 'user:1'], $response->getCacheableMetadata()->getCacheTags() ); } diff --git a/tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php b/tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php index 732dca0..bcbf144 100644 --- a/tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php +++ b/tests/src/Unit/Normalizer/ConfigEntityNormalizerTest.php @@ -8,7 +8,6 @@ use Drupal\jsonapi\ResourceType\ResourceType; use Drupal\jsonapi\ResourceType\ResourceTypeRepository; use Drupal\jsonapi\Normalizer\ConfigEntityNormalizer; use Drupal\jsonapi\LinkManager\LinkManager; -use Drupal\jsonapi\Normalizer\ScalarNormalizer; use Drupal\Tests\UnitTestCase; use Prophecy\Argument; use Symfony\Component\Serializer\Serializer; @@ -42,8 +41,7 @@ class ConfigEntityNormalizerTest extends UnitTestCase { $this->prophesize(EntityTypeManagerInterface::class)->reveal() ); - $normalizers = [new ScalarNormalizer()]; - $serializer = new Serializer($normalizers, []); + $serializer = new Serializer([], []); $this->normalizer->setSerializer($serializer); }