hasMoreRecords example

/** * {@inheritdoc} */
  public function renderPager() {
    return TRUE;
  }

  /** * {@inheritdoc} */
  public function renderMoreLink() {
    $hasMoreRecords = !empty($this->view->pager) && $this->view->pager->hasMoreRecords();
    if ($this->isMoreEnabled() && ($this->useMoreAlways() || $hasMoreRecords)) {
      $url = $this->getMoreUrl();

      return [
        '#type' => 'more_link',
        '#url' => $url,
        '#title' => $this->useMoreText(),
        '#view' => $this->view,
      ];
    }
  }

  
/** * Tests the hasMoreRecords() method. * * @dataProvider providerTestHasMoreRecords * * @see \Drupal\views\Plugin\views\pager\PagerPluginBase::hasMoreRecords() */
  public function testHasMoreRecords($items_per_page$total_items$current_page$has_more_records) {
    $this->pager->setItemsPerPage($items_per_page);
    $this->pager->total_items = $total_items;
    $this->pager->setCurrentPage($current_page);
    $this->assertEquals($has_more_records$this->pager->hasMoreRecords());
  }

  /** * Provides test data for the hasMoreRecord method test. * * @see self::testHasMoreRecords */
  public function providerTestHasMoreRecords() {
    return [
      // No items per page, so there can't be more available records.       [0, 0, 0, FALSE],
      [
Home | Imprint | This part of the site doesn't use cookies.