You are here

protected function OffsetPageNormalizer::expand in JSON:API 8

1 call to OffsetPageNormalizer::expand()
OffsetPageNormalizer::denormalize in src/Normalizer/OffsetPageNormalizer.php
Denormalizes data back into an object of the given class.

File

src/Normalizer/OffsetPageNormalizer.php, line 41

Class

OffsetPageNormalizer
The normalizer used for JSON API pagination.

Namespace

Drupal\jsonapi\Normalizer

Code

protected function expand($data) {
  if (!is_array($data)) {
    throw new BadRequestHttpException('The page parameter needs to be an array.');
  }
  $expanded = $data + [
    OffsetPage::OFFSET_KEY => OffsetPage::DEFAULT_OFFSET,
    OffsetPage::SIZE_KEY => OffsetPage::SIZE_MAX,
  ];
  if ($expanded[OffsetPage::SIZE_KEY] > OffsetPage::SIZE_MAX) {
    $expanded[OffsetPage::SIZE_KEY] = OffsetPage::SIZE_MAX;
  }
  return $expanded;
}