Skip to content
Snippets Groups Projects

:construction_worker:‍♀️update gitlab CI configuration to test on D9 and D10.

Merged Elliot Ward requested to merge issue/jsonapi_page_limit-3375871:3375871-gitlab into 8.x-1.x
Files
4
@@ -12,6 +12,7 @@ use Drupal\Core\Routing\RequestContext;
use Drupal\Core\Session\AccountInterface;
use Drupal\jsonapi\Access\EntityAccessChecker;
use Drupal\jsonapi\Context\FieldResolver;
use Drupal\jsonapi\Controller\EntityResource as CoreEntityResource;
use Drupal\jsonapi\IncludeResolver;
use Drupal\jsonapi\Query\OffsetPage;
use Drupal\jsonapi\ResourceType\ResourceType;
@@ -19,7 +20,10 @@ use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\SerializerInterface;
class EntityResource extends \Drupal\jsonapi\Controller\EntityResource {
/**
* Extension to core EntityResource facilitating custom page limits.
*/
class EntityResource extends CoreEntityResource {
/**
* An array of paths and their maximum item count.
@@ -42,6 +46,38 @@ class EntityResource extends \Drupal\jsonapi\Controller\EntityResource {
*/
private $pathMatcher;
/**
* 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 \Drupal\Core\Routing\RequestContext $request_context
* The request context.
* @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
* The path matcher.
* @param array|null $size_max
* An array of maximum size configuration.
*/
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, RequestContext $request_context, PathMatcherInterface $path_matcher, ?array $size_max) {
parent::__construct($entity_type_manager, $field_manager, $resource_type_repository, $renderer, $entity_repository, $include_resolver, $entity_access_checker, $field_resolver, $serializer, $time, $user);
$this->sizeMax = $size_max;
@@ -78,11 +114,12 @@ class EntityResource extends \Drupal\jsonapi\Controller\EntityResource {
*/
private function getMax(array $page_params) {
$path = $this->requestContext->getPathInfo();
$matches = array_filter($this->sizeMax, function($key) use ($path) {
$matches = array_filter($this->sizeMax, function ($key) use ($path) {
return $this->pathMatcher->matchPath($path, $key);
}, ARRAY_FILTER_USE_KEY);
// In case of multiple matches, use the first match.
$size_max = reset($matches) ?? OffsetPage::SIZE_MAX;
return min($page_params['limit'], $size_max);
}
}
Loading