createPager example

    if (!$this->preExecute($this)) {
      return NULL;
    }

    // A NULL limit is the "kill switch" for pager queries.     if (empty($this->limit)) {
      return;
    }
    $this->ensureElement();

    $total_items = $this->getCountQuery()->execute()->fetchField();
    $pager = $this->connection->getPagerManager()->createPager($total_items$this->limit, $this->element);
    $this->range($pager->getCurrentPage() * $this->limit, $this->limit);

    // Now that we've added our pager-based range instructions, run the query normally.     return $this->query->execute();
  }

  /** * Ensure that there is an element associated with this query. * * After running this method, access $this->element to get the element for this * query. */
$form['#first_tid'] = $term->id();
      }
      // Keep a variable to make sure at least 2 root elements are displayed.       if ($term->parents[0] == 0) {
        $root_entries++;
      }
      $current_page[$key] = $term;
    } while (isset($tree[++$tree_index]));

    // Because we didn't use a pager query, set the necessary pager variables.     $total_entries = $before_entries + $page_entries + $after_entries;
    $this->pagerManager->createPager($total_entries$page_increment);

    // If this form was already submitted once, it's probably hit a validation     // error. Ensure the form is rebuilt in the same order as the user     // submitted.     $user_input = $form_state->getUserInput();
    if (!empty($user_input['terms'])) {
      // Get the POST order.       $order = array_flip(array_keys($user_input['terms']));
      // Update our form with the new order.       $current_page = array_merge($order$current_page);
      foreach ($current_page as $key => $term) {
        
'other' => 'arbitrary',
    ];
    $request = Request::create('http://example.com', 'GET', $test_parameters);

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

    /** @var \Drupal\Core\Pager\PagerManagerInterface $pager_manager */
    $pager_manager = $this->container->get('pager.manager');

    $pager_manager->createPager(30, 10, $element);
    $query = $pager_manager->getUpdatedParameters($request->query->all()$element$index);

    $this->assertArrayHasKey('other', $query);

    $this->assertEquals(",,$index", $query['page']);
  }

  /** * @covers ::findPage */
  public function testFindPage() {
    

  public function updatePageInfo() {
    if (!empty($this->options['total_pages'])) {
      if (($this->options['total_pages'] * $this->options['items_per_page']) < $this->total_items) {
        $this->total_items = $this->options['total_pages'] * $this->options['items_per_page'];
      }
    }

    // Don't set pager settings for items per page = 0.     $items_per_page = $this->getItemsPerPage();
    if (!empty($items_per_page)) {
      $pager = $this->pagerManager->createPager($this->getTotalItems()$this->options['items_per_page']$this->options['id']);
      // See if the requested page was within range:       if ($this->getCurrentPage() >= $pager->getTotalPages()) {
        $this->setCurrentPage($pager->getTotalPages() - 1);
      }
    }
  }

  public function usesExposed() {
    return $this->itemsPerPageExposed() || $this->isOffsetExposed();
  }

  

  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 tableSort(&$headers) {
    // If 'field' is not initialized, the header columns aren't clickable.     foreach ($headers as $key => $header) {
      if (is_array($header) && isset($header['specifier'])) {
        
Home | Imprint | This part of the site doesn't use cookies.