You are here

public static function Pagerer::create in Pagerer 8

Same name in this branch
  1. 8 src/Pagerer.php \Drupal\pagerer\Pagerer::create()
  2. 8 src/Plugin/views/pager/Pagerer.php \Drupal\pagerer\Plugin\views\pager\Pagerer::create()

Instantiates a new instance of this class.

This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.

Parameters

\Symfony\Component\DependencyInjection\ContainerInterface $container: The service container this instance should use.

Overrides ContainerInjectionInterface::create

1 call to Pagerer::create()
PagererFactory::get in src/PagererFactory.php
Returns the pager object for the specified pager element.

File

src/Pagerer.php, line 77

Class

Pagerer
Pagerer pager management class.

Namespace

Drupal\pagerer

Code

public static function create(ContainerInterface $container, $element = NULL) {
  $instance = new static($container
    ->get('pagerer.factory'), $container
    ->get('request_stack'));

  // Set the pager element.
  $instance->element = $element;

  // Set the pager adaptive keys if they exist in the query string.
  if ($page_ak = $instance
    ->getCurrentRequest()->query
    ->get('page_ak')) {

    // A 'page_ak' query parameter exists in the calling URL.
    $adaptive_keys = explode(',', $page_ak);
    if (isset($adaptive_keys[$element])) {
      $instance
        ->setAdaptiveKeys($adaptive_keys[$element]);
    }
  }
  return $instance;
}