Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
b7a6866c
Commit
b7a6866c
authored
Jan 18, 2015
by
Alex Pott
Browse files
Issue
#1588138
by mondrake: pager_query_add_page() overrides parameters passed programmatically
parent
629d4cbf
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/includes/pager.inc
View file @
b7a6866c
...
...
@@ -304,8 +304,11 @@ function pager_query_add_page(array $query, $element, $index) {
if
(
$new_page
=
implode
(
','
,
pager_load_array
(
$page_new
[
$element
],
$element
,
explode
(
','
,
$page
))))
{
$query
[
'page'
]
=
$new_page
;
}
if
(
$query_pager
=
pager_get_query_parameters
())
{
$query
=
array_merge
(
$query
,
$query_pager
);
// Merge the query parameters passed to this function with the parameters
// from the current request. In case of collision, the parameters passed
// into this function take precedence.
if
(
$current_request_query
=
pager_get_query_parameters
())
{
$query
=
array_merge
(
$current_request_query
,
$query
);
}
return
$query
;
}
...
...
core/modules/system/src/Tests/Pager/PagerTest.php
View file @
b7a6866c
...
...
@@ -2,7 +2,7 @@
/**
* @file
*
Definition of
Drupal\system\Tests\Pager\PagerTest.
*
Contains \
Drupal\system\Tests\Pager\PagerTest.
*/
namespace
Drupal\system\Tests\Pager
;
...
...
@@ -21,7 +21,7 @@ class PagerTest extends WebTestBase {
*
* @var array
*/
public
static
$modules
=
array
(
'dblog'
);
public
static
$modules
=
array
(
'dblog'
,
'pager_test'
);
protected
$profile
=
'testing'
;
...
...
@@ -62,6 +62,25 @@ function testActiveClass() {
$this
->
assertPagerItems
(
$current_page
);
}
/**
* Test proper functioning of the query parameters.
*/
protected
function
testPagerQueryParameters
()
{
// First page.
$this
->
drupalGet
(
'pager-test/query-parameters'
);
$this
->
assertText
(
t
(
'Pager calls: 0'
),
'Initial call to pager shows 0 calls.'
);
// Go to last page, the count of pager calls need to go to 1.
$elements
=
$this
->
xpath
(
'//li[contains(@class, :class)]/a'
,
array
(
':class'
=>
'pager__item--last'
));
$this
->
drupalGet
(
$GLOBALS
[
'base_root'
]
.
$elements
[
0
][
'href'
],
array
(
'external'
=>
TRUE
));
$this
->
assertText
(
t
(
'Pager calls: 1'
),
'First link call to pager shows 1 calls.'
);
// Go back to first page, the count of pager calls need to go to 2.
$elements
=
$this
->
xpath
(
'//li[contains(@class, :class)]/a'
,
array
(
':class'
=>
'pager__item--first'
));
$this
->
drupalGet
(
$GLOBALS
[
'base_root'
]
.
$elements
[
0
][
'href'
],
array
(
'external'
=>
TRUE
));
$this
->
assertText
(
t
(
'Pager calls: 2'
),
'Second link call to pager shows 2 calls.'
);
}
/**
* Asserts pager items and links.
*
...
...
core/modules/system/tests/modules/pager_test/pager_test.info.yml
0 → 100644
View file @
b7a6866c
type
:
module
core
:
8.x
name
:
'
Pager
Test'
description
:
'
Support
module
for
pager
tests.'
package
:
Testing
version
:
VERSION
core/modules/system/tests/modules/pager_test/pager_test.routing.yml
0 → 100644
View file @
b7a6866c
pager_test.query_parameters
:
path
:
'
/pager-test/query-parameters'
defaults
:
_title
:
'
Pager
using
query
parameters
for
testing'
_controller
:
'
\Drupal\pager_test\Controller\PagerTestController::queryParameters'
requirements
:
_access
:
'
TRUE'
core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php
0 → 100644
View file @
b7a6866c
<?php
/**
* @file
* Contains \Drupal\pager_test\Controller\PagerTestController.
*/
namespace
Drupal\pager_test\Controller
;
use
Drupal\Core\Controller\ControllerBase
;
/**
* Controller routine for testing the pager.
*/
class
PagerTestController
extends
ControllerBase
{
/**
* Returns a pager with 'parameters' variable.
*
* The 'pager_calls' parameter counts the calls to the pager, subsequent
* to the initial call.
*/
public
function
queryParameters
()
{
// Example query.
$header_0
=
array
(
array
(
'data'
=>
'wid'
),
array
(
'data'
=>
'type'
),
array
(
'data'
=>
'timestamp'
),
);
$query_0
=
db_select
(
'watchdog'
,
'd'
)
->
extend
(
'Drupal\Core\Database\Query\PagerSelectExtender'
)
->
element
(
0
);
$query_0
->
fields
(
'd'
,
array
(
'wid'
,
'type'
,
'timestamp'
));
$result_0
=
$query_0
->
limit
(
5
)
->
orderBy
(
'd.wid'
)
->
execute
();
$rows_0
=
array
();
foreach
(
$result_0
as
$row
)
{
$rows_0
[]
=
array
(
'data'
=>
(
array
)
$row
);
}
$build
[
'pager_table_0'
]
=
array
(
'#theme'
=>
'table'
,
'#header'
=>
$header_0
,
'#rows'
=>
$rows_0
,
'#empty'
=>
$this
->
t
(
"There are no watchdog records found in the db"
),
);
// Counter of calls to the current pager.
$query_params
=
pager_get_query_parameters
();
$pager_calls
=
isset
(
$query_params
[
'pager_calls'
])
?
(
$query_params
[
'pager_calls'
]
?
$query_params
[
'pager_calls'
]
:
0
)
:
0
;
$build
[
'l_pager_pager_0'
]
=
array
(
'#markup'
=>
$this
->
t
(
'Pager calls: @pager_calls'
,
array
(
'@pager_calls'
=>
$pager_calls
)));
// Pager.
$build
[
'pager_pager_0'
]
=
array
(
'#theme'
=>
'pager'
,
'#element'
=>
0
,
'#parameters'
=>
array
(
'pager_calls'
=>
++
$pager_calls
,
),
);
return
$build
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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