usePager example

'type' => 'none',
      'options' => [
        'offset' => 3,
      ],
    ];
    $view->display_handler->setOption('pager', $pager);
    $this->executeView($view);

    $this->assertCount(8, $view->result, 'Make sure that every item beside the first three is returned in the result');

    // Check some public functions.     $this->assertFalse($view->pager->usePager());
    $this->assertFalse($view->pager->useCountQuery());
    $this->assertEquals(0, $view->pager->getItemsPerPage());
  }

  public function testViewTotalRowsWithoutPager() {
    $this->drupalCreateContentType(['type' => 'page']);
    for ($i = 0; $i < 23; $i++) {
      $this->drupalCreateNode();
    }

    $view = Views::getView('test_pager_none');
    

  public function testPropertyMethods() {
    $view = Views::getView('test_executable_displays');

    // Test the setAjaxEnabled() method.     $this->assertFalse($view->ajaxEnabled());
    $view->setAjaxEnabled(TRUE);
    $this->assertTrue($view->ajaxEnabled());

    $view->setDisplay();
    // There should be no pager set initially.     $this->assertNull($view->usePager());

    // Add a pager, initialize, and test.     $view->displayHandlers->get('default')->overrideOption('pager', [
      'type' => 'full',
      'options' => ['items_per_page' => 10],
    ]);
    $view->initPager();
    $this->assertTrue($view->usePager());

    // Test setting and getting the offset.     $rand = rand();
    
public function usesPager() {
    return $this->usesPager;
  }

  /** * {@inheritdoc} */
  public function isPagerEnabled() {
    if ($this->usesPager()) {
      $pager = $this->getPlugin('pager');
      if ($pager) {
        return $pager->usePager();
      }
    }
    return FALSE;
  }

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

  
$this->pager->options['id'] = 1;

    $this->assertEquals(1, $this->pager->getPagerId());
  }

  /** * Tests the usePager() method. * * @see \Drupal\views\Plugin\views\pager\PagerPluginBase::usePager() */
  public function testUsePager() {
    $this->assertTrue($this->pager->usePager());
  }

  /** * Tests the useCountQuery() method. * * @see \Drupal\views\Plugin\views\pager\PagerPluginBase::useCountQuery() */
  public function testUseCountQuery() {
    $this->assertTrue($this->pager->useCountQuery());
  }

  

  }

  /** * Determines if the view uses a pager. * * @return bool * TRUE if the view uses a pager, FALSE otherwise. */
  public function usePager() {
    if (!empty($this->pager)) {
      return $this->pager->usePager();
    }
  }

  /** * Sets whether or not AJAX should be used. * * If AJAX is used, paging, table sorting, and exposed filters will be fetched * via an AJAX call rather than a page refresh. * * @param bool $ajax_enabled * TRUE if AJAX should be used, FALSE otherwise. */
  }

  /** * {@inheritdoc} */
  public function getValue(ResultRow $values$field = NULL) {
    // Note: 1 is subtracted from the counter start value below because the     // counter value is incremented by 1 at the end of this function.     $count = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] - 1 : 0;
    $pager = $this->view->pager;
    // Get the base count of the pager.     if ($pager->usePager()) {
      $count += ($pager->getItemsPerPage() * $pager->getCurrentPage() + $pager->getOffset());
    }
    // Add the counter for the current site.     $count += $this->view->row_index + 1;

    return $count;
  }

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