You are here

protected function Formatter::calculateItemsPerPage in RESTful 7.2

Helper function that calculates the number of items per page.

Parameters

ResourceInterface $resource: The associated resource.

Return value

int The items per page.

3 calls to Formatter::calculateItemsPerPage()
FormatterHalJson::addHateoas in src/Plugin/formatter/FormatterHalJson.php
Add HATEOAS links to list of item.
FormatterJson::addHateoas in src/Plugin/formatter/FormatterJson.php
Add HATEOAS links to list of item.
FormatterJsonApi::addHateoas in src/Plugin/formatter/FormatterJsonApi.php
Add HATEOAS links to list of item.

File

src/Plugin/formatter/Formatter.php, line 327
Contains \Drupal\restful\Plugin\formatter\Formatter

Class

Formatter
Class Formatter.

Namespace

Drupal\restful\Plugin\formatter

Code

protected function calculateItemsPerPage(ResourceInterface $resource) {
  $data_provider = $resource
    ->getDataProvider();
  $max_range = $data_provider
    ->getRange();
  $original_input = $resource
    ->getRequest()
    ->getPagerInput();
  $items_per_page = empty($original_input['size']) ? $max_range : $original_input['size'];
  return $items_per_page > $max_range ? $max_range : $items_per_page;
}