findPage example


  public function __construct(PagerParametersInterface $pager_params) {
    $this->pagerParams = $pager_params;
  }

  /** * {@inheritdoc} */
  public function createPager($total$limit$element = 0) {
    $currentPage = $this->pagerParams->findPage($element);
    $pager = new Pager($total$limit$currentPage);
    $this->setPager($pager$element);
    return $pager;
  }

  /** * {@inheritdoc} */
  public function getPager($element = 0) {
    return $this->pagers[$element] ?? NULL;
  }

  

  public function setCurrentPage($number = NULL) {
    if (isset($number)) {
      $this->current_page = max(0, $number);
      return;
    }

    $this->current_page = max(0, $this->pagerParameters->findPage($this->options['id']));
  }

  public function getPagerTotal() {
    if ($items_per_page = intval($this->getItemsPerPage())) {
      return ceil($this->total_items / $items_per_page);
    }
    else {
      return 1;
    }
  }

  

  public function testFindPage() {
    $request = Request::create('http://example.com', 'GET', ['page' => '0,10']);

    /** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */
    $request_stack = $this->container->get('request_stack');
    $request_stack->push($request);

    $pager_params = $this->container->get('pager.parameters');

    $this->assertEquals(10, $pager_params->findPage(1));
  }

  /** * @covers ::getQueryParameters */
  public function testGetQueryParameters() {
    $test_parameters = [
      'other' => 'arbitrary',
    ];
    $request = Request::create('http://example.com', 'GET', array_merge(['page' => '0,10']$test_parameters));

    

  public function getContext($pager_id = NULL) {
    // The value of the 'page' query argument contains the information that     // controls *all* pagers.     if ($pager_id === NULL) {
      return $this->pagerParams->getPagerParameter();
    }

    return $pager_id . '.' . $this->pagerParams->findPage($pager_id);
  }

  /** * {@inheritdoc} */
  public function getCacheableMetadata($pager_id = NULL) {
    return new CacheableMetadata();
  }

}
return $this;
  }

  /** * Gets the total number of results and initialize a pager for the query. * * The pager can be disabled by either setting the pager limit to 0, or by * setting this query to be a count query. */
  protected function initializePager() {
    if ($this->pager && !empty($this->pager['limit']) && !$this->count) {
      $page = \Drupal::service('pager.parameters')->findPage($this->pager['element']);
      $count_query = clone $this;
      $this->pager['total'] = $count_query->count()->execute();
      $this->pager['start'] = $page * $this->pager['limit'];
      \Drupal::service('pager.manager')->createPager($this->pager['total']$this->pager['limit']$this->pager['element']);
      $this->range($this->pager['start']$this->pager['limit']);
    }
  }

  /** * {@inheritdoc} */
  

  public function buildForm(array $form, FormStateInterface $form_state, VocabularyInterface $taxonomy_vocabulary = NULL) {
    $form_state->set(['taxonomy', 'vocabulary']$taxonomy_vocabulary);
    $vocabulary_hierarchy = $this->storageController->getVocabularyHierarchyType($taxonomy_vocabulary->id());
    $parent_fields = FALSE;

    $page = $this->pagerManager->findPage();
    // Number of terms per page.     $page_increment = $this->config('taxonomy.settings')->get('terms_per_page_admin');
    // Elements shown on this page.     $page_entries = 0;
    // Elements at the root level before this page.     $before_entries = 0;
    // Elements at the root level after this page.     $after_entries = 0;
    // Elements at the root level on this page.     $root_entries = 0;

    

  public function testFindPage() {
    $request = Request::create('http://example.com', 'GET', ['page' => '0,10']);

    /** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */
    $request_stack = $this->container->get('request_stack');
    $request_stack->push($request);

    $pager_manager = $this->container->get('pager.manager');

    $this->assertEquals(10, $pager_manager->findPage(1));
  }

  /** * @covers ::getMaxPagerElementId * * @dataProvider providerTestGetMaxPagerElementId */
  public function testGetMaxPagerElementId(array $elements, int $expected_max_element_id): void {
    /** @var \Drupal\Core\Pager\PagerManagerInterface $pager_manager */
    $pager_manager = $this->container->get('pager.manager');

    
Home | Imprint | This part of the site doesn't use cookies.