getMaxPagerElementId example

    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. */
  protected function ensureElement() {
    if (!isset($this->element)) {
      $this->element($this->connection->getPagerManager()->getMaxPagerElementId() + 1);
    }
  }

  /** * Specify the count query object to use for this pager. * * You will rarely need to specify a count query directly. If not specified, * one is generated off of the pager query itself. * * @param \Drupal\Core\Database\Query\SelectInterface $query * The count query object. It must return a single row with a single column, * which is the total number of records. */
$this->latestRevision = FALSE;
    return $this;
  }

  /** * {@inheritdoc} */
  public function pager($limit = 10, $element = NULL) {
    // Even when not using SQL, storing the element PagerSelectExtender is as     // good as anywhere else.     if (!isset($element)) {
      $element = \Drupal::service('pager.manager')->getMaxPagerElementId() + 1;
    }

    $this->pager = [
      'limit' => $limit,
      'element' => $element,
    ];
    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. */

  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');

    foreach ($elements as $element) {
      $pager_manager->createPager(30, 10, $element);
    }

    $this->assertEquals($expected_max_element_id$pager_manager->getMaxPagerElementId());
  }

  /** * Provides test cases for PagerManagerTest::testGetMaxPagerElementId(). * * @return array * An array of test cases, each which the following values: * - Array of elements to pass to PagerManager::createPager(). * - The expected value returned by PagerManager::getMaxPagerElementId(). */
  public function providerTestGetMaxPagerElementId(): array {
    
return $this->pagerParams->findPage($pager_id);
  }

  /** * {@inheritdoc} */
  public function getUpdatedParameters(array $query$element$index) {
    // Build the 'page' query parameter. This is built based on the current     // page of each pager element (or NULL if the pager is not set), with the     // exception of the requested page index for the current element.     $element_pages = [];
    $max = $this->getMaxPagerElementId();
    for ($i = 0; $i <= $max$i++) {
      $currentPage = ($pager = $this->getPager($i)) ? $pager->getCurrentPage() : NULL;
      $element_pages[] = ($i == $element) ? $index : $currentPage;
    }
    $query['page'] = implode(',', $element_pages);

    // Merge the query parameters passed to this function with the parameters     // from the current request. In case of collision, the parameters passed     // into this function take precedence.     if ($current_query = $this->pagerParams->getQueryParameters()) {
      $query = array_merge($current_query$query);
    }
Home | Imprint | This part of the site doesn't use cookies.