summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authore0ipso2018-12-26 07:08:05 (GMT)
committerMateu Aguiló Bosch2018-12-26 07:08:05 (GMT)
commit80c415f6eca2244933e10cc9b59850e7b9a7da41 (patch)
treed3b95b34c026d1a319b5d6cd1d58e7d84048fe0a
parentf1e6fe2f68ef8f108127bc1f08ece1256f2be149 (diff)
Issue #3022475 by e0ipso: Drop support for JSON:API 2.x in JSON:API Extras 2.x8.x-2.158.x-2.x
-rw-r--r--composer.json2
-rw-r--r--jsonapi_extras.services.yml14
-rw-r--r--src/Entity/JsonapiResourceConfig.php27
-rw-r--r--src/EntityToJsonApi.php18
-rw-r--r--src/JsonapiExtrasServiceProvider.php18
-rw-r--r--src/Normalizer/EntityNormalizerTrait.php12
-rw-r--r--src/ResourceType/ConfigurableResourceTypeRepository.php35
-rw-r--r--src/SerializerDecorator.php140
-rw-r--r--tests/src/Functional/JsonExtrasApiFunctionalTest.php18
-rw-r--r--tests/src/Kernel/Controller/EntityResourceTest.php123
-rw-r--r--tests/src/Kernel/EntityToJsonApiTest.php12
11 files changed, 48 insertions, 371 deletions
diff --git a/composer.json b/composer.json
index 7ac5e3d..72acd02 100644
--- a/composer.json
+++ b/composer.json
@@ -11,7 +11,7 @@
],
"require": {
"drupal/core": "^8.5",
- "drupal/jsonapi": "^1.22 || ^2.0-rc1",
+ "drupal/jsonapi": "^1.22",
"e0ipso/shaper": "^1"
}
}
diff --git a/jsonapi_extras.services.yml b/jsonapi_extras.services.yml
index 317a31c..86c3108 100644
--- a/jsonapi_extras.services.yml
+++ b/jsonapi_extras.services.yml
@@ -6,20 +6,18 @@ services:
- '@entity_type.manager'
- '@plugin.manager.resource_field_enhancer'
tags:
- - { name: normalizer, priority: 1025, format: api_json }
+ - { name: jsonapi_normalizer_do_not_use_removal_imminent, priority: 25, format: api_json }
serializer.normalizer.entity.jsonapi_extras:
class: Drupal\jsonapi_extras\Normalizer\ContentEntityNormalizer
parent: serializer.normalizer.entity.jsonapi
- calls:
- - [setSerializer, ['@jsonapi.serializer_do_not_use_removal_imminent']]
tags:
- - { name: normalizer, priority: 1022, format: api_json }
+ - { name: jsonapi_normalizer_do_not_use_removal_imminent, priority: 22, format: api_json }
serializer.normalizer.config_entity.jsonapi_extras:
class: Drupal\jsonapi_extras\Normalizer\ConfigEntityNormalizer
parent: serializer.normalizer.config_entity.jsonapi
tags:
- - { name: normalizer, priority: 1022, format: api_json }
+ - { name: jsonapi_normalizer_do_not_use_removal_imminent, priority: 22, format: api_json }
plugin.manager.resource_field_enhancer:
class: Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager
@@ -35,9 +33,3 @@ services:
jsonapi_extras.entity.to_jsonapi:
class: Drupal\jsonapi_extras\EntityToJsonApi
arguments: ['@jsonapi.serializer_do_not_use_removal_imminent', '@jsonapi.resource_type.repository', '@current_user', '@request_stack', '%jsonapi.base_path%']
-
- jsonapi.serializer_do_not_use_removal_imminent.jsonapi_extras:
- class: \Drupal\jsonapi_extras\SerializerDecorator
- public: false
- decorates: jsonapi.serializer_do_not_use_removal_imminent
- arguments: ['@jsonapi.serializer_do_not_use_removal_imminent.jsonapi_extras.inner']
diff --git a/src/Entity/JsonapiResourceConfig.php b/src/Entity/JsonapiResourceConfig.php
index e12d8dc..6b54ab5 100644
--- a/src/Entity/JsonapiResourceConfig.php
+++ b/src/Entity/JsonapiResourceConfig.php
@@ -102,31 +102,4 @@ class JsonapiResourceConfig extends ConfigEntityBase {
}
}
- /**
- * Returns a field mapping as expected by JSON API 2.x' ResourceType class.
- *
- * @see \Drupal\jsonapi\ResourceType\ResourceType::__construct()
- */
- public function getFieldMapping() {
- $resource_fields = $this->get('resourceFields') ?: [];
-
- $mapping = [];
- foreach ($resource_fields as $resource_field) {
- $field_name = $resource_field['fieldName'];
- if ($resource_field['disabled'] === TRUE) {
- $mapping[$field_name] = FALSE;
- continue;
- }
-
- if (($alias = $resource_field['publicName']) && $alias !== $field_name) {
- $mapping[$field_name] = $alias;
- continue;
- }
-
- $mapping[$field_name] = TRUE;
- }
-
- return $mapping;
- }
-
}
diff --git a/src/EntityToJsonApi.php b/src/EntityToJsonApi.php
index 9c1706b..60b0800 100644
--- a/src/EntityToJsonApi.php
+++ b/src/EntityToJsonApi.php
@@ -4,11 +4,10 @@ namespace Drupal\jsonapi_extras;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
-use Drupal\jsonapi\JsonApiResource\EntityCollection;
+use Drupal\jsonapi\Resource\JsonApiDocumentTopLevel;
use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface;
use Drupal\jsonapi\Routing\Routes;
use Drupal\jsonapi\Serializer\Serializer;
-use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Serializer\SerializerInterface;
@@ -58,7 +57,7 @@ class EntityToJsonApi {
/**
* EntityToJsonApi constructor.
*
- * @param \Drupal\jsonapi\Serializer\Serializer|\Drupal\jsonapi_extras\SerializerDecorator $serializer
+ * @param \Symfony\Component\Serializer\SerializerInterface $serializer
* The serializer.
* @param \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository
* The resource type repository.
@@ -70,7 +69,7 @@ class EntityToJsonApi {
* The JSON API base path.
*/
public function __construct(SerializerInterface $serializer, ResourceTypeRepositoryInterface $resource_type_repository, AccountInterface $current_user, RequestStack $request_stack, $jsonapi_base_path) {
- assert($serializer instanceof Serializer || $serializer instanceof SerializerDecorator);
+ assert($serializer instanceof Serializer);
$this->serializer = $serializer;
$this->resourceTypeRepository = $resource_type_repository;
$this->currentUser = $current_user;
@@ -80,9 +79,6 @@ class EntityToJsonApi {
assert(isset($jsonapi_base_path[1]));
assert(substr($jsonapi_base_path, -1) !== '/');
$this->jsonApiBasePath = $jsonapi_base_path;
- $this->classToUse = ConfigurableResourceTypeRepository::isJsonApi2x()
- ? '\Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel'
- : '\Drupal\jsonapi\Resource\JsonApiDocumentTopLevel';
}
/**
@@ -101,9 +97,7 @@ class EntityToJsonApi {
foreach ($includes as $field_name) {
$referenced_entities = array_merge($referenced_entities, $entity->get($field_name)->referencedEntities());
}
- $document = ConfigurableResourceTypeRepository::isJsonApi2x()
- ? new $this->classToUse($entity, new EntityCollection($referenced_entities), [])
- : new $this->classToUse($entity);
+ $document = new JsonApiDocumentTopLevel($entity);
return $this->serializer->serialize($document,
'api_json',
$this->calculateContext($entity, $includes)
@@ -126,9 +120,7 @@ class EntityToJsonApi {
foreach ($includes as $field_name) {
$referenced_entities = array_merge($referenced_entities, $entity->get($field_name)->referencedEntities());
}
- $document = ConfigurableResourceTypeRepository::isJsonApi2x()
- ? new $this->classToUse($entity, new EntityCollection($referenced_entities), [])
- : new $this->classToUse($entity);
+ $document = new JsonApiDocumentTopLevel($entity);
return $this->serializer->normalize($document,
'api_json',
$this->calculateContext($entity, $includes)
diff --git a/src/JsonapiExtrasServiceProvider.php b/src/JsonapiExtrasServiceProvider.php
index 3d6d9c7..f67efe6 100644
--- a/src/JsonapiExtrasServiceProvider.php
+++ b/src/JsonapiExtrasServiceProvider.php
@@ -28,24 +28,6 @@ class JsonapiExtrasServiceProvider extends ServiceProviderBase {
$definition->addMethodCall('setConfigFactory', [new Reference('config.factory')]);
}
- // Make all three of the normalizers that JSON API Extras overrides private
- // untagged services, to ensure that JSON API Extras' overrides continue to
- // work in JSON API 2.x, using core's @serializer service.
- if ($container->has('serializer.normalizer.field_item.jsonapi')) {
- $container->getDefinition('serializer.normalizer.field_item.jsonapi')->setPrivate(TRUE)->clearTags();
- }
- if ($container->has('serializer.normalizer.entity.jsonapi')) {
- $container->getDefinition('serializer.normalizer.entity.jsonapi')->setPrivate(TRUE)->clearTags();
- }
- if ($container->has('serializer.normalizer.config_entity.jsonapi')) {
- $container->getDefinition('serializer.normalizer.config_entity.jsonapi')->setPrivate(TRUE)->clearTags();
- }
-
- // Break a circular dependency.
- // @see \Drupal\jsonapi_extras\SerializerDecorator::lazilyInitialize()
- $definition = $container->getDefinition('jsonapi.serializer_do_not_use_removal_imminent');
- $definition->removeMethodCall('setFallbackNormalizer');
-
$settings = BootstrapConfigStorageFactory::get()
->read('jsonapi_extras.settings');
diff --git a/src/Normalizer/EntityNormalizerTrait.php b/src/Normalizer/EntityNormalizerTrait.php
index 84a11d6..389a475 100644
--- a/src/Normalizer/EntityNormalizerTrait.php
+++ b/src/Normalizer/EntityNormalizerTrait.php
@@ -16,19 +16,11 @@ trait EntityNormalizerTrait {
* The input data to modify.
* @param \Drupal\jsonapi\ResourceType\ResourceType $resource_type
* Contains the info about the resource type.
- * @param string $format
- * (optional) Format from which the given data was extracted. Only required
- * for JSON API 2.x.
- * @param array $context
- * (optional) Options available to the denormalizer. Only required for JSON
- * API 2.x.
*
* @return array
* The modified input data.
- *
- * @todo Make the last 2 args non-optional when JSON API 2.x is required.
*/
- protected function prepareInput(array $data, ResourceType $resource_type, $format = NULL, array $context = []) {
+ protected function prepareInput(array $data, ResourceType $resource_type) {
/** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $field_storage_definitions */
$field_storage_definitions = \Drupal::service('entity_field.manager')
->getFieldStorageDefinitions(
@@ -70,7 +62,7 @@ trait EntityNormalizerTrait {
$data_internal[$internal_name] = $field_value;
}
- return parent::prepareInput($data_internal, $resource_type, $format, $context);
+ return parent::prepareInput($data_internal, $resource_type);
}
/**
diff --git a/src/ResourceType/ConfigurableResourceTypeRepository.php b/src/ResourceType/ConfigurableResourceTypeRepository.php
index 3b35dbf..1e6fcfd 100644
--- a/src/ResourceType/ConfigurableResourceTypeRepository.php
+++ b/src/ResourceType/ConfigurableResourceTypeRepository.php
@@ -5,7 +5,6 @@ namespace Drupal\jsonapi_extras\ResourceType;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
-use Drupal\Core\Extension\ModuleHandler;
use Drupal\jsonapi\ResourceType\ResourceTypeRepository;
use Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager;
use Drupal\Core\Config\ConfigFactoryInterface;
@@ -65,34 +64,6 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
protected $resourceConfigs;
/**
- * Detects whether this site has JSON API 1.x or 2.x installed.
- *
- * @return bool
- * TRUE if JSON API 2.x is installed. FALSE otherwise.
- *
- * @todo Remove this when JSON API Extras drops support for JSON API 1.x.
- */
- public static function isJsonApi2x() {
- static $is_2x = NULL;
-
- if ($is_2x !== NULL) {
- return $is_2x;
- }
- $extension = \Drupal::service('extension.list.module')->get('jsonapi');
- $version = $extension->info['version'];
- if ($version === NULL) {
- // When running a git clone of the module we will not get a version number
- // here. In this case we resort to checking for a 2.x only service.
- $is_2x = \Drupal::hasService('jsonapi.include_resolver');
- }
- else {
- $dependency = ModuleHandler::parseDependency('jsonapi(>= 8.x-2.0-beta1)');
- $is_2x = drupal_check_incompatibility($dependency, $version) === NULL;
- }
- return $is_2x;
- }
-
- /**
* Injects the entity repository.
*
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
@@ -124,14 +95,8 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
/**
* {@inheritdoc}
- *
- * @todo Remove this when JSON API Extras drops support for JSON API 1.x.
*/
public function all() {
- if (static::isJsonApi2x()) {
- return parent::all();
- }
-
if (empty($this->all)) {
$all = parent::all();
array_walk($all, [$this, 'injectAdditionalServicesToResourceType']);
diff --git a/src/SerializerDecorator.php b/src/SerializerDecorator.php
deleted file mode 100644
index a57dd01..0000000
--- a/src/SerializerDecorator.php
+++ /dev/null
@@ -1,140 +0,0 @@
-<?php
-
-namespace Drupal\jsonapi_extras;
-
-use Symfony\Component\Serializer\SerializerInterface;
-use Symfony\Component\Serializer\Encoder\DecoderInterface;
-use Symfony\Component\Serializer\Encoder\EncoderInterface;
-use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
-use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
-use Drupal\jsonapi\Serializer\Serializer;
-
-/**
- * A decorated JSON API serializer, with lazily initialized fallback serializer.
- */
-class SerializerDecorator implements SerializerInterface, NormalizerInterface, DenormalizerInterface, EncoderInterface, DecoderInterface {
-
- /**
- * The decorated JSON API serializer service.
- *
- * @var \Drupal\jsonapi\Serializer\Serializer
- */
- protected $decoratedSerializer;
-
- /**
- * Whether the lazy dependency has been initialized.
- *
- * @var bool
- */
- protected $isInitialized = FALSE;
-
- /**
- * Constructs a SerializerDecorator.
- *
- * @param \Drupal\jsonapi\Serializer\Serializer $serializer
- * The decorated JSON API serializer.
- */
- public function __construct(Serializer $serializer) {
- $this->decoratedSerializer = $serializer;
- }
-
- /**
- * Lazily initializes the fallback serializer for the JSON API serializer.
- *
- * Breaks circular dependency.
- */
- protected function lazilyInitialize() {
- if (!$this->isInitialized) {
- $core_serializer = \Drupal::service('serializer');
- $this->decoratedSerializer->setFallbackNormalizer($core_serializer);
- $this->isInitialized = TRUE;
- }
- }
-
- /**
- * Relays a method call to the decorated service.
- *
- * @param string $method_name
- * The method to invoke on the decorated serializer.
- * @param array $args
- * The arguments to pass to the invoked method on the decorated serializer.
- *
- * @return mixed
- * The return value.
- */
- protected function relay($method_name, array $args) {
- $this->lazilyInitialize();
- return call_user_func_array([$this->decoratedSerializer, $method_name], $args);
- }
-
- /**
- * {@inheritdoc}
- */
- public function decode($data, $format, array $context = []) {
- return $this->relay(__FUNCTION__, func_get_args());
- }
-
- /**
- * {@inheritdoc}
- */
- public function denormalize($data, $class, $format = NULL, array $context = []) {
- return $this->relay(__FUNCTION__, func_get_args());
- }
-
- /**
- * {@inheritdoc}
- */
- public function deserialize($data, $type, $format, array $context = []) {
- return $this->relay(__FUNCTION__, func_get_args());
- }
-
- /**
- * {@inheritdoc}
- */
- public function encode($data, $format, array $context = []) {
- return $this->relay(__FUNCTION__, func_get_args());
- }
-
- /**
- * {@inheritdoc}
- */
- public function normalize($object, $format = NULL, array $context = []) {
- return $this->relay(__FUNCTION__, func_get_args());
- }
-
- /**
- * {@inheritdoc}
- */
- public function supportsDecoding($format) {
- return $this->relay(__FUNCTION__, func_get_args());
- }
-
- /**
- * {@inheritdoc}
- */
- public function serialize($data, $format, array $context = []) {
- return $this->relay(__FUNCTION__, func_get_args());
- }
-
- /**
- * {@inheritdoc}
- */
- public function supportsDenormalization($data, $type, $format = NULL) {
- return $this->relay(__FUNCTION__, func_get_args());
- }
-
- /**
- * {@inheritdoc}
- */
- public function supportsEncoding($format) {
- return $this->relay(__FUNCTION__, func_get_args());
- }
-
- /**
- * {@inheritdoc}
- */
- public function supportsNormalization($data, $format = NULL) {
- return $this->relay(__FUNCTION__, func_get_args());
- }
-
-}
diff --git a/tests/src/Functional/JsonExtrasApiFunctionalTest.php b/tests/src/Functional/JsonExtrasApiFunctionalTest.php
index e286ebf..2704510 100644
--- a/tests/src/Functional/JsonExtrasApiFunctionalTest.php
+++ b/tests/src/Functional/JsonExtrasApiFunctionalTest.php
@@ -8,7 +8,6 @@ use Drupal\Core\Url;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\jsonapi_extras\Entity\JsonapiResourceConfig;
-use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTestBase;
@@ -182,14 +181,8 @@ class JsonExtrasApiFunctionalTest extends JsonApiFunctionalTestBase {
// 13. Test a disabled related resource of single cardinality.
$this->drupalGet('/api/taxonomy_term/tags/' . $this->tags[0]->uuid() . '/vid');
$this->assertSession()->statusCodeEquals(404);
- $output = Json::decode($this->drupalGet('/api/taxonomy_term/tags/' . $this->tags[0]->uuid() . '/relationships/vid'));
- if (ConfigurableResourceTypeRepository::isJsonApi2x()) {
- $this->assertSession()->statusCodeEquals(200);
- $this->assertSame(NULL, $output['data']);
- }
- else {
- $this->assertSession()->statusCodeEquals(404);
- }
+ Json::decode($this->drupalGet('/api/taxonomy_term/tags/' . $this->tags[0]->uuid() . '/relationships/vid'));
+ $this->assertSession()->statusCodeEquals(404);
// 14. Test a disabled related resource of multiple cardinality.
$this->tags[1]->vocabs->set(0, 'tags');
@@ -275,12 +268,7 @@ class JsonExtrasApiFunctionalTest extends JsonApiFunctionalTestBase {
$this->assertEquals(201, $response->getStatusCode());
$this->assertArrayHasKey('internalId', $created_response['data']['attributes']);
$this->assertCount(2, $created_response['data']['relationships']['tags']['data']);
- if (ConfigurableResourceTypeRepository::isJsonApi2x()) {
- $this->assertSame($created_response['data']['links']['self']['href'], $response->getHeader('Location')[0]);
- }
- else {
- $this->assertSame($created_response['data']['links']['self'], $response->getHeader('Location')[0]);
- }
+ $this->assertSame($created_response['data']['links']['self'], $response->getHeader('Location')[0]);
$date = new \DateTime($body['data']['attributes']['timestamp']);
$created_node = Node::load($created_response['data']['attributes']['internalId']);
$this->assertSame((int) $date->format('U'), (int) $created_node->get('field_timestamp')->value);
diff --git a/tests/src/Kernel/Controller/EntityResourceTest.php b/tests/src/Kernel/Controller/EntityResourceTest.php
index 3ccc4d2..8fd2125 100644
--- a/tests/src/Kernel/Controller/EntityResourceTest.php
+++ b/tests/src/Kernel/Controller/EntityResourceTest.php
@@ -7,8 +7,6 @@ use Drupal\Core\Config\ConfigException;
use Drupal\jsonapi\ResourceType\ResourceType;
use Drupal\jsonapi\Controller\EntityResource;
use Drupal\jsonapi\Resource\JsonApiDocumentTopLevel;
-use Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel as JsonApiDocumentTopLevel2;
-use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\user\Entity\Role;
@@ -21,10 +19,6 @@ use Symfony\Component\HttpFoundation\Request;
* @group jsonapi_extras
* @group legacy
*
- * When upgrading JSON API Extras to work with JSON API 2.x revert to this patch
- * instead.
- * @see https://www.drupal.org/project/jsonapi_extras/issues/2995804#comment-12752336
- *
* @internal
*/
class EntityResourceTest extends KernelTestBase {
@@ -67,39 +61,19 @@ class EntityResourceTest extends KernelTestBase {
->grantPermission('administer content types')
->save();
$resource_type = new ResourceType('node', 'article', NULL);
- if (ConfigurableResourceTypeRepository::isJsonApi2x()) {
- $entity_resource = new EntityResource(
- $this->container->get('entity_type.manager'),
- $this->container->get('entity_field.manager'),
- $this->container->get('jsonapi.link_manager'),
- $this->container->get('jsonapi.resource_type.repository'),
- $this->container->get('renderer'),
- $this->container->get('entity.repository'),
- $this->container->get('jsonapi.include_resolver'),
- $this->container->get('renderer')
- );
- $response = $entity_resource->createIndividual($resource_type, $node_type, new Request());
- }
- else {
- $entity_resource = new EntityResource(
- $resource_type,
- $this->container->get('entity_type.manager'),
- $this->container->get('entity_field.manager'),
- $this->container->get('plugin.manager.field.field_type'),
- $this->container->get('jsonapi.link_manager'),
- $this->container->get('jsonapi.resource_type.repository'),
- $this->container->get('renderer')
- );
- $response = $entity_resource->createIndividual($node_type, new Request());
- }
+ $entity_resource = new EntityResource(
+ $resource_type,
+ $this->container->get('entity_type.manager'),
+ $this->container->get('entity_field.manager'),
+ $this->container->get('plugin.manager.field.field_type'),
+ $this->container->get('jsonapi.link_manager'),
+ $this->container->get('jsonapi.resource_type.repository'),
+ $this->container->get('renderer')
+ );
+ $response = $entity_resource->createIndividual($node_type, new Request());
// As a side effect, the node type will also be saved.
$this->assertNotEmpty($node_type->id());
- if (ConfigurableResourceTypeRepository::isJsonApi2x()) {
- $this->assertInstanceOf(JsonApiDocumentTopLevel2::class, $response->getResponseData());
- }
- else {
- $this->assertInstanceOf(JsonApiDocumentTopLevel::class, $response->getResponseData());
- }
+ $this->assertInstanceOf(JsonApiDocumentTopLevel::class, $response->getResponseData());
$this->assertEquals('test', $response->getResponseData()->getData()->id());
$this->assertEquals(201, $response->getStatusCode());
}
@@ -135,39 +109,19 @@ class EntityResourceTest extends KernelTestBase {
$request = new Request([], [], [], [], [], [], $payload);
$resource_type = new ResourceType('node', 'article', NULL);
- if (ConfigurableResourceTypeRepository::isJsonApi2x()) {
- $entity_resource = new EntityResource(
- $this->container->get('entity_type.manager'),
- $this->container->get('entity_field.manager'),
- $this->container->get('jsonapi.link_manager'),
- $this->container->get('jsonapi.resource_type.repository'),
- $this->container->get('renderer'),
- $this->container->get('entity.repository'),
- $this->container->get('jsonapi.include_resolver'),
- $this->container->get('renderer')
- );
- $response = $entity_resource->patchIndividual($resource_type, $node_type, $parsed_node_type, $request);
- }
- else {
- $entity_resource = new EntityResource(
- $resource_type,
- $this->container->get('entity_type.manager'),
- $this->container->get('entity_field.manager'),
- $this->container->get('plugin.manager.field.field_type'),
- $this->container->get('jsonapi.link_manager'),
- $this->container->get('jsonapi.resource_type.repository'),
- $this->container->get('renderer')
- );
- $response = $entity_resource->patchIndividual($node_type, $parsed_node_type, $request);
- }
+ $entity_resource = new EntityResource(
+ $resource_type,
+ $this->container->get('entity_type.manager'),
+ $this->container->get('entity_field.manager'),
+ $this->container->get('plugin.manager.field.field_type'),
+ $this->container->get('jsonapi.link_manager'),
+ $this->container->get('jsonapi.resource_type.repository'),
+ $this->container->get('renderer')
+ );
+ $response = $entity_resource->patchIndividual($node_type, $parsed_node_type, $request);
// As a side effect, the node will also be saved.
- if (ConfigurableResourceTypeRepository::isJsonApi2x()) {
- $this->assertInstanceOf(JsonApiDocumentTopLevel2::class, $response->getResponseData());
- }
- else {
- $this->assertInstanceOf(JsonApiDocumentTopLevel::class, $response->getResponseData());
- }
+ $this->assertInstanceOf(JsonApiDocumentTopLevel::class, $response->getResponseData());
$updated_node_type = $response->getResponseData()->getData();
$this->assertInstanceOf(NodeType::class, $updated_node_type);
// If the field is ignored then we should not see a difference.
@@ -229,30 +183,15 @@ class EntityResourceTest extends KernelTestBase {
->grantPermission('administer content types')
->save();
$resource_type = new ResourceType('node', 'article', NULL);
- if (ConfigurableResourceTypeRepository::isJsonApi2x()) {
- $entity_resource = new EntityResource(
- $this->container->get('entity_type.manager'),
- $this->container->get('entity_field.manager'),
- $this->container->get('jsonapi.link_manager'),
- $this->container->get('jsonapi.resource_type.repository'),
- $this->container->get('renderer'),
- $this->container->get('entity.repository'),
- $this->container->get('jsonapi.include_resolver'),
- $this->container->get('renderer')
- );
-
- }
- else {
- $entity_resource = new EntityResource(
- $resource_type,
- $this->container->get('entity_type.manager'),
- $this->container->get('entity_field.manager'),
- $this->container->get('plugin.manager.field.field_type'),
- $this->container->get('jsonapi.link_manager'),
- $this->container->get('jsonapi.resource_type.repository'),
- $this->container->get('renderer')
- );
- }
+ $entity_resource = new EntityResource(
+ $resource_type,
+ $this->container->get('entity_type.manager'),
+ $this->container->get('entity_field.manager'),
+ $this->container->get('plugin.manager.field.field_type'),
+ $this->container->get('jsonapi.link_manager'),
+ $this->container->get('jsonapi.resource_type.repository'),
+ $this->container->get('renderer')
+ );
$response = $entity_resource->deleteIndividual($node_type, new Request());
// As a side effect, the node will also be deleted.
$count = $this->container->get('entity_type.manager')
diff --git a/tests/src/Kernel/EntityToJsonApiTest.php b/tests/src/Kernel/EntityToJsonApiTest.php
index a57d4f8..0c99d1f 100644
--- a/tests/src/Kernel/EntityToJsonApiTest.php
+++ b/tests/src/Kernel/EntityToJsonApiTest.php
@@ -7,7 +7,6 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\file\Entity\File;
use Drupal\jsonapi\LinkManager\LinkManager;
-use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\taxonomy\Entity\Term;
@@ -172,9 +171,6 @@ class EntityToJsonApiTest extends JsonapiKernelTestBase {
* @covers ::normalize
*/
public function testSerialize() {
- $tid_public_name = ConfigurableResourceTypeRepository::isJsonApi2x()
- ? 'drupal_internal__tid'
- : 'tid';
$entities = [
[
$this->node,
@@ -184,7 +180,7 @@ class EntityToJsonApiTest extends JsonapiKernelTestBase {
'type' => 'taxonomy_term--tags',
'id' => $this->term1->uuid(),
'attributes' => [
- $tid_public_name => (int) $this->term1->id(),
+ 'tid' => (int) $this->term1->id(),
'name' => $this->term1->label(),
],
],
@@ -192,7 +188,7 @@ class EntityToJsonApiTest extends JsonapiKernelTestBase {
'type' => 'taxonomy_term--tags',
'id' => $this->term2->uuid(),
'attributes' => [
- $tid_public_name => (int) $this->term2->id(),
+ 'tid' => (int) $this->term2->id(),
'name' => $this->term2->label(),
],
],
@@ -257,9 +253,7 @@ class EntityToJsonApiTest extends JsonapiKernelTestBase {
static::assertNotEmpty($structured['data']['type']);
static::assertNotEmpty($structured['data']['id']);
static::assertNotEmpty($structured['data']['attributes']);
- if (!ConfigurableResourceTypeRepository::isJsonApi2x()) {
- static::assertInternalType('string', $structured['links']['self']);
- }
+ static::assertInternalType('string', $structured['links']['self']);
}
/**