PagerParameters.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Pager/PagerParameters.php
  2. 8.9.x core/lib/Drupal/Core/Pager/PagerParameters.php
  3. 10 core/lib/Drupal/Core/Pager/PagerParameters.php

Namespace

Drupal\Core\Pager

File

core/lib/Drupal/Core/Pager/PagerParameters.php

View source
<?php

namespace Drupal\Core\Pager;

use Drupal\Component\Utility\UrlHelper;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * Provides pager information contained within the current request.
 *
 * @see \Drupal\Core\Pager\PagerManagerInterface
 */
class PagerParameters implements PagerParametersInterface {
    
    /**
     * The HTTP request stack.
     *
     * @var \Symfony\Component\HttpFoundation\RequestStack
     */
    protected $requestStack;
    
    /**
     * Construct a PagerManager object.
     *
     * @param \Symfony\Component\HttpFoundation\RequestStack $stack
     *   The current HTTP request stack.
     */
    public function __construct(RequestStack $stack) {
        $this->requestStack = $stack;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getQueryParameters() {
        $request = $this->requestStack
            ->getCurrentRequest();
        if ($request) {
            return UrlHelper::filterQueryParameters($request->query
                ->all(), [
                'page',
            ]);
        }
        return [];
    }
    
    /**
     * {@inheritdoc}
     */
    public function findPage($pager_id = 0) {
        $pages = $this->getPagerQuery();
        return (int) ($pages[$pager_id] ?? 0);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getPagerQuery() {
        $query = $this->getPagerParameter();
        return !empty($query) ? explode(',', $query) : [];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getPagerParameter() {
        $request = $this->requestStack
            ->getCurrentRequest();
        if ($request) {
            return $request->query
                ->get('page', '');
        }
        return '';
    }

}

Classes

Title Deprecated Summary
PagerParameters Provides pager information contained within the current request.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.