Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions modules/next/modules/next_jsonapi/next_jsonapi.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ parameters:
services:
jsonapi.entity_resource:
class: Drupal\next_jsonapi\Controller\EntityResource
autowire: true
arguments:
- '@entity_type.manager'
- '@entity_field.manager'
- '@jsonapi.resource_type.repository'
- '@renderer'
- '@entity.repository'
- '@jsonapi.include_resolver'
- '@jsonapi.entity_access_checker'
- '@jsonapi.field_resolver'
- '@jsonapi.serializer'
- '@datetime.time'
- '@current_user'
- '%next_jsonapi.size_max%'
51 changes: 12 additions & 39 deletions modules/next/modules/next_jsonapi/src/Controller/EntityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@

namespace Drupal\next_jsonapi\Controller;

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\jsonapi\Access\EntityAccessChecker;
use Drupal\jsonapi\Context\FieldResolver;
use Drupal\jsonapi\Controller\EntityResource as JsonApiEntityResource;
use Drupal\jsonapi\IncludeResolver;
use Drupal\jsonapi\Query\OffsetPage;
use Drupal\jsonapi\ResourceType\ResourceType;
use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\SerializerInterface;

/**
* Process all entity requests.
Expand All @@ -28,39 +17,23 @@ class EntityResource extends JsonApiEntityResource {
*
* @var int
*/
protected $maxSize;
protected int $maxSize;

/**
* EntityResource constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager
* The entity type field manager.
* @param \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository
* The JSON:API resource type repository.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
* @param \Drupal\jsonapi\IncludeResolver $include_resolver
* The include resolver.
* @param \Drupal\jsonapi\Access\EntityAccessChecker $entity_access_checker
* The JSON:API entity access checker.
* @param \Drupal\jsonapi\Context\FieldResolver $field_resolver
* The JSON:API field resolver.
* @param \Symfony\Component\Serializer\SerializerInterface|\Symfony\Component\Serializer\Normalizer\DenormalizerInterface $serializer
* The JSON:API serializer.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\Core\Session\AccountInterface $user
* The current user account.
* @param int $max_size
* The offset max size.
* @param mixed ...$args
* All constructor arguments.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $field_manager, ResourceTypeRepositoryInterface $resource_type_repository, RendererInterface $renderer, EntityRepositoryInterface $entity_repository, IncludeResolver $include_resolver, EntityAccessChecker $entity_access_checker, FieldResolver $field_resolver, SerializerInterface $serializer, TimeInterface $time, AccountInterface $user, int $max_size) {
parent::__construct($entity_type_manager, $field_manager, $resource_type_repository, $renderer, $entity_repository, $include_resolver, $entity_access_checker, $field_resolver, $serializer, $time, $user);
$this->maxSize = $max_size;
public function __construct(...$args) {
// Pop the last argument as $maxSize.
$this->maxSize = array_pop($args);

// Forward the remaining arguments to the parent constructor.
// We handle it this way because the parent constructor arguments
// differ between Drupal 10 and Drupal 11, so using ...$args
// ensures compatibility across versions.
parent::__construct(...$args);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function register(ContainerBuilder $container) {
if ($container->hasDefinition('jsonapi.entity_resource')) {
$definition = $container->getDefinition('jsonapi.entity_resource');
$definition->setClass('Drupal\next_jsonapi\Controller\EntityResource')
->setAutowired(TRUE)
->addArgument('%next_jsonapi.size_max%');
}
}
Expand Down
Loading