diff --git a/lib/Drupal/views/Plugin/views/pager/Full.php b/lib/Drupal/views/Plugin/views/pager/Full.php index 68ab731253fdcf04f77cdffb6d55a2a889375570..0f6369c345b18ab723f109c623c5c6c37c64bda7 100644 --- a/lib/Drupal/views/Plugin/views/pager/Full.php +++ b/lib/Drupal/views/Plugin/views/pager/Full.php @@ -317,7 +317,7 @@ function render($input) { */ function set_current_page($number = NULL) { if (isset($number)) { - $this->current_page = $number; + $this->current_page = max(0, $number); return; } @@ -338,11 +338,8 @@ function set_current_page($number = NULL) { $pager_page_array[$i] = empty($page[$i]) ? 0 : $page[$i]; } - $this->current_page = intval($pager_page_array[$this->options['id']]); - - if ($this->current_page < 0) { - $this->current_page = 0; - } + // Don't allow the number to be less than zero. + $this->current_page = max(0, intval($pager_page_array[$this->options['id']])); } function get_pager_total() { @@ -380,14 +377,10 @@ function update_page_info() { // Calculate and set the count of available pages. $pager_total[$this->options['id']] = $this->get_pager_total(); - // @todo Use set_current_page() here: http://drupal.org/node/1758766 + // See if the requested page was within range: if ($this->current_page >= $pager_total[$this->options['id']]) { // Pages are numbered from 0 so if there are 10 pages, the last page is 9. - $this->current_page = $pager_total[$this->options['id']] - 1; - } - // See if the requested page was within range: - if ($this->current_page < 0) { - $this->current_page = 0; + $this->set_current_page($pager_total[$this->options['id']] - 1); } // Put this number in to guarantee that we do not generate notices when the pager diff --git a/lib/Drupal/views/Tests/Plugin/PagerTest.php b/lib/Drupal/views/Tests/Plugin/PagerTest.php index 3f2f37d42736c979114bb22cb9911fbd82826e56..a7d9ba7f08f2c5d27e267b1f18a4003eab90469e 100644 --- a/lib/Drupal/views/Tests/Plugin/PagerTest.php +++ b/lib/Drupal/views/Tests/Plugin/PagerTest.php @@ -319,6 +319,10 @@ function testPagerApi() { $rand_number = rand(6, 11); $view->pager->set_current_page($rand_number); $this->assertEqual($view->getCurrentPage(), $rand_number, 'Make sure get_current_page uses the settings of set_current_page.'); + + // Set an invalid page and make sure the method takes care about it. + $view->setCurrentPage(-1); + $this->assertEqual($view->getCurrentPage(), 0, 'Make sure setCurrentPage always sets a valid page number.'); } }