Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
25416c1e
Commit
25416c1e
authored
Sep 08, 2012
by
tim.plunkett
Committed by
tim.plunkett
Oct 21, 2012
Browse files
Issue
#1758766
by tim.plunkett, dawehner: Clean up current_page() code and API usage.
parent
cf22d23b
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/Drupal/views/Plugin/views/pager/Full.php
View file @
25416c1e
...
...
@@ -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
...
...
lib/Drupal/views/Tests/Plugin/PagerTest.php
View file @
25416c1e
...
...
@@ -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.'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment