You are here

class PagererFactory in Pagerer 8

Provides a factory for Pagerer pagers.

Hierarchy

Expanded class hierarchy of PagererFactory

3 files declare their use of PagererFactory
PagererConfigForm.php in src/Form/PagererConfigForm.php
PagererPresetFormBase.php in src/Form/PagererPresetFormBase.php
PagererPresetPaneResetForm.php in src/Form/PagererPresetPaneResetForm.php
1 string reference to 'PagererFactory'
pagerer.services.yml in ./pagerer.services.yml
pagerer.services.yml
1 service uses PagererFactory
pagerer.factory in ./pagerer.services.yml
Drupal\pagerer\PagererFactory

File

src/PagererFactory.php, line 8

Namespace

Drupal\pagerer
View source
class PagererFactory implements PagererFactoryInterface {

  /**
   * The array of pager objects.
   *
   * @var \Drupal\pagerer\Pagerer[]
   */
  protected $pagers = [];

  /**
   * {@inheritdoc}
   */
  public function initPagers() {
    global $pager_total;
    if (!empty($pager_total) && count($pager_total) > 0) {
      $max_pager_id = 0;
      foreach ($pager_total as $id => $value) {
        $max_pager_id = $id > $max_pager_id ? $id : $max_pager_id;
      }
      for ($i = 0; $i <= $max_pager_id; $i++) {
        $this
          ->get($i);
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function get($element) {
    if (!isset($this->pagers[$element])) {

      // Fill any gap in the sequence.
      for ($i = max(count($this->pagers) - 1, 0); $i < $element; $i++) {
        $this
          ->get($i);
      }
      $this->pagers[$element] = Pagerer::create(\Drupal::getContainer(), $element);
    }
    return $this->pagers[$element];
  }

  /**
   * {@inheritdoc}
   */
  public function all() {
    return $this->pagers;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PagererFactory::$pagers protected property The array of pager objects.
PagererFactory::all public function Returns the array of pager objects. Overrides PagererFactoryInterface::all
PagererFactory::get public function Returns the pager object for the specified pager element. Overrides PagererFactoryInterface::get
PagererFactory::initPagers public function Initialises the pagers. Overrides PagererFactoryInterface::initPagers