Issue #2798947 by Lendude, loopduplicate, rocketeerbkw, netdreamer, LoMo, Kristen Pol, rwam, Berdir, dawehner: Views pagers include ajax metadata

merge-requests/1654/head
Alex Pott 2018-04-06 09:41:40 +01:00
parent e817928144
commit 48726e6908
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
2 changed files with 32 additions and 7 deletions

View File

@ -132,7 +132,20 @@ class ViewAjaxController implements ContainerInjectionInterface {
// Remove all of this stuff from the query of the request so it doesn't
// end up in pagers and tablesort URLs.
foreach (['view_name', 'view_display_id', 'view_args', 'view_path', 'view_dom_id', 'pager_element', 'view_base_path', AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER] as $key) {
// @todo Remove this parsing once these are removed from the request in
// https://www.drupal.org/node/2504709.
foreach ([
'view_name',
'view_display_id',
'view_args',
'view_path',
'view_dom_id',
'pager_element',
'view_base_path',
AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER,
FormBuilderInterface::AJAX_FORM_REQUEST,
MainContentViewSubscriber::WRAPPER_FORMAT,
] as $key) {
$request->query->remove($key);
$request->request->remove($key);
}
@ -152,6 +165,7 @@ class ViewAjaxController implements ContainerInjectionInterface {
// Add all POST data, because AJAX is always a post and many things,
// such as tablesorts, exposed filters and paging assume GET.
$request_all = $request->request->all();
unset($request_all['ajax_page_state']);
$query_all = $request->query->all();
$request->query->replace($request_all + $query_all);
@ -159,13 +173,7 @@ class ViewAjaxController implements ContainerInjectionInterface {
// @see the redirect.destination service.
$origin_destination = $path;
// Remove some special parameters you never want to have part of the
// destination query.
$used_query_parameters = $request->query->all();
// @todo Remove this parsing once these are removed from the request in
// https://www.drupal.org/node/2504709.
unset($used_query_parameters[FormBuilderInterface::AJAX_FORM_REQUEST], $used_query_parameters[MainContentViewSubscriber::WRAPPER_FORMAT], $used_query_parameters['ajax_page_state']);
$query = UrlHelper::buildQuery($used_query_parameters);
if ($query != '') {
$origin_destination .= '?' . $query;

View File

@ -86,6 +86,10 @@ class PaginationAJAXTest extends JavascriptTestBase {
$rows = $page->findAll('css', 'tbody tr');
$this->assertCount(5, $rows);
$this->assertContains('Node 6 content', $rows[0]->getHtml());
$link = $page->findLink('Go to page 3');
// Test that no unwanted parameters are added to the URL.
$this->assertEquals('?status=All&type=All&langcode=All&items_per_page=5&order=changed&sort=asc&title=&page=2', $link->getAttribute('href'));
$this->assertNoDuplicateAssetsOnPage();
$this->clickLink('Go to page 3');
$session_assert->assertWaitOnAjaxRequest();
@ -115,4 +119,17 @@ class PaginationAJAXTest extends JavascriptTestBase {
$this->assertContains('Node 11 content', $rows[0]->getHtml());
}
/**
* Assert that assets are not loaded twice on a page.
*/
protected function assertNoDuplicateAssetsOnPage() {
/** @var \Behat\Mink\Element\NodeElement[] $scripts */
$scripts = $this->getSession()->getPage()->findAll('xpath', '//script');
$script_src = [];
foreach ($scripts as $script) {
$this->assertFalse(in_array($script->getAttribute('src'), $script_src));
$script_src[] = $script->getAttribute('src');
}
}
}