Skip to content
Snippets Groups Projects
Commit 25416c1e authored by Tim Plunkett's avatar Tim Plunkett Committed by Tim Plunkett
Browse files

Issue #1758766 by tim.plunkett, dawehner: Clean up current_page() code and API usage.

parent cf22d23b
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -317,7 +317,7 @@ function render($input) { ...@@ -317,7 +317,7 @@ function render($input) {
*/ */
function set_current_page($number = NULL) { function set_current_page($number = NULL) {
if (isset($number)) { if (isset($number)) {
$this->current_page = $number; $this->current_page = max(0, $number);
return; return;
} }
...@@ -338,11 +338,8 @@ function set_current_page($number = NULL) { ...@@ -338,11 +338,8 @@ function set_current_page($number = NULL) {
$pager_page_array[$i] = empty($page[$i]) ? 0 : $page[$i]; $pager_page_array[$i] = empty($page[$i]) ? 0 : $page[$i];
} }
$this->current_page = intval($pager_page_array[$this->options['id']]); // Don't allow the number to be less than zero.
$this->current_page = max(0, intval($pager_page_array[$this->options['id']]));
if ($this->current_page < 0) {
$this->current_page = 0;
}
} }
function get_pager_total() { function get_pager_total() {
...@@ -380,14 +377,10 @@ function update_page_info() { ...@@ -380,14 +377,10 @@ function update_page_info() {
// Calculate and set the count of available pages. // Calculate and set the count of available pages.
$pager_total[$this->options['id']] = $this->get_pager_total(); $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']]) { 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. // 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; $this->set_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;
} }
// Put this number in to guarantee that we do not generate notices when the pager // Put this number in to guarantee that we do not generate notices when the pager
......
...@@ -319,6 +319,10 @@ function testPagerApi() { ...@@ -319,6 +319,10 @@ function testPagerApi() {
$rand_number = rand(6, 11); $rand_number = rand(6, 11);
$view->pager->set_current_page($rand_number); $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.'); $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.');
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment