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

Breadcrumb

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

function OffsetPage::createFromQueryParameter

Creates an OffsetPage object from a query parameter.

Parameters

mixed $parameter: The `page` query parameter from the Symfony request object.

Return value

static An OffsetPage object with defaults.

1 call to OffsetPage::createFromQueryParameter()
EntityResource::getJsonApiParams in core/modules/jsonapi/src/Controller/EntityResource.php
Extracts JSON:API query parameters from the request.

File

core/modules/jsonapi/src/Query/OffsetPage.php, line 110

Class

OffsetPage
Value object for containing the requested offset and page parameters.

Namespace

Drupal\jsonapi\Query

Code

public static function createFromQueryParameter($parameter) {
    if (!is_array($parameter)) {
        $cacheability = (new CacheableMetadata())->addCacheContexts([
            'url.query_args:page',
        ]);
        throw new CacheableBadRequestHttpException($cacheability, 'The page parameter needs to be an array.');
    }
    $expanded = $parameter + [
        static::OFFSET_KEY => static::DEFAULT_OFFSET,
        static::SIZE_KEY => static::SIZE_MAX,
    ];
    if ($expanded[static::SIZE_KEY] > static::SIZE_MAX) {
        $expanded[static::SIZE_KEY] = static::SIZE_MAX;
    }
    return new static($expanded[static::OFFSET_KEY], $expanded[static::SIZE_KEY]);
}

API Navigation

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