Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EntityResource.php

function EntityResource::getPagerQueries

Get the query param array.

Parameters

string $link_id: The name of the pagination link requested.

int $offset: The starting index.

int $size: The pagination page size.

array $query: The query parameters.

int $total: The total size of the collection.

Return value

array The pagination query param array.

1 call to EntityResource::getPagerQueries()
EntityResource::getPagerLinks in core/modules/jsonapi/src/Controller/EntityResource.php
Get the pager links for a given request object.

File

core/modules/jsonapi/src/Controller/EntityResource.php, line 1339

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

protected static function getPagerQueries($link_id, $offset, $size, array $query = [], $total = 0) {
    $extra_query = [];
    switch ($link_id) {
        case 'next':
            $extra_query = [
                'page' => [
                    'offset' => $offset + $size,
                    'limit' => $size,
                ],
            ];
            break;
        case 'first':
            $extra_query = [
                'page' => [
                    'offset' => 0,
                    'limit' => $size,
                ],
            ];
            break;
        case 'last':
            if ($total) {
                $extra_query = [
                    'page' => [
                        'offset' => (ceil($total / $size) - 1) * $size,
                        'limit' => $size,
                    ],
                ];
            }
            break;
        case 'prev':
            $extra_query = [
                'page' => [
                    'offset' => max($offset - $size, 0),
                    'limit' => $size,
                ],
            ];
            break;
    }
    return array_merge($query, $extra_query);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal