Commit 25416c1e authored by tim.plunkett's avatar tim.plunkett Committed by tim.plunkett

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

parent cf22d23b
......@@ -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
......
......@@ -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.');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment