class PagerParameters

Same name in other branches
  1. 9 core/lib/Drupal/Core/Pager/PagerParameters.php \Drupal\Core\Pager\PagerParameters
  2. 10 core/lib/Drupal/Core/Pager/PagerParameters.php \Drupal\Core\Pager\PagerParameters
  3. 11.x core/lib/Drupal/Core/Pager/PagerParameters.php \Drupal\Core\Pager\PagerParameters

Provides pager information contained within the current request.

Hierarchy

Expanded class hierarchy of PagerParameters

See also

\Drupal\Core\Pager\PagerManagerInterface

1 file declares its use of PagerParameters
SqlBase.php in core/modules/views/src/Plugin/views/pager/SqlBase.php
1 string reference to 'PagerParameters'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses PagerParameters
pager.parameters in core/core.services.yml
Drupal\Core\Pager\PagerParameters

File

core/lib/Drupal/Core/Pager/PagerParameters.php, line 13

Namespace

Drupal\Core\Pager
View source
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 '';
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
PagerParameters::$requestStack protected property The HTTP request stack.
PagerParameters::findPage public function Returns the current page being requested for display within a pager. Overrides PagerParametersInterface::findPage
PagerParameters::getPagerParameter public function Gets the 'page' query parameter for the current request. Overrides PagerParametersInterface::getPagerParameter
PagerParameters::getPagerQuery public function Gets the request query parameter. Overrides PagerParametersInterface::getPagerQuery
PagerParameters::getQueryParameters public function Gets all request URL query parameters that are unrelated to paging. Overrides PagerParametersInterface::getQueryParameters
PagerParameters::__construct public function Construct a PagerManager object.

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