Coming from #2048309: Views UI Preview - navigation is broken, see comment #1 point 3 .

If a contextual filter is specified in the preview textbox, this input gets lost when navigating to a different page on the preview.

Steps to reproduce:

  1. Devel create 50 nodes of type 'article' and 'basic page'
  2. Clone the 'frontpage' view
  3. Change display format to e.g. table, selecting 'title' and 'type' fields as columns in the table
  4. Add a contextual filter to the cloned view, for the 'type' field
  5. Type 'page' in the textbox for the contextual filter preview
  6. Click 'Update preview'
  7. You get a table of only 'basic page' nodes
  8. Click any page link in the pager

Expected result:
A second page of 'basic page' nodes

Actual result:
A mix of 'basic page' and 'article' nodes, and the contextual filter textbox is void.

Per #31:

Looks like we may not need to push/pop the request in ViewUI::renderPreview anymore. I think that was relevant when that method was calling drupal_render() so that the pager could use a different 'current' request to build its links. But now, since #2412805: View preview does not attach assets provided by plugins, ViewUI::renderPreview returns a render array, so if we push a request and then pop it within the same method this ends up as a no-op, since the rendering occurs at a later stage.

We can clean up some old stale code to get the expected result.

Comments

mondrake’s picture

Issue tags: +VDC

tagging

dawehner’s picture

What happened when you have done the same in Drupal 7?

dawehner’s picture

Issue summary: View changes

added steps to reproduce

mondrake’s picture

Just checked in D7, repeating steps 1-8 as per the summary, the result is the 'expected' one.

dawehner’s picture

SO this is clearly a bug.

dawehner’s picture

Issue summary: View changes

formatting

mondrake’s picture

effulgentsia’s picture

Priority: Normal » Major
Issue tags: +Needs tests
mondrake’s picture

Status: Active » Needs review
StatusFileSize
new3.24 KB

This is replicating the approach in #2237001-17: Remove no longer needed _current_path() fallback for early bootstrap, i.e. move the contextual filters from the path to a query parameter (only in the context of a view preview, of course). In this case it looks like we would not have to bother manipulating the _current_path at all.

Just throwing as an idea. I'm sure there are better ways...

mgifford’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The last submitted patch, 7: 2066207-preview_filters-7.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new3.25 KB

trying...

Status: Needs review » Needs work

The last submitted patch, 11: 2066207-11.patch, failed testing.

mondrake’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests, -Needs reroll
StatusFileSize
new9.84 KB
new13.09 KB

Rerolled, and added a test + test only patch.

The last submitted patch, 13: 2066207-13-test-only.patch, failed testing.

effulgentsia’s picture

Issue tags: +blocker
dawehner’s picture

Note: #2362227: Replace all instances of current_path() is also removing the call to current_path()

mondrake’s picture

Issue tags: -blocker +Needs reroll

#2362227: Replace all instances of current_path() removed both current_path() and _current_path(), so this is no longer a blocker. However, t seems that this issue is still valid. Patch in #13 needs a reroll for sure, but maybe a different approach too, now a request object is pushed on the stack and working on that maybe a better option than the query parameter.

mondrake queued 13: 2066207-13.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 13: 2066207-13.patch, failed testing.

The last submitted patch, 13: 2066207-13-test-only.patch, failed testing.

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new11.78 KB

Reroll of patch in #13.

This is still using a query parameter to store the contextual filter for the pager link, i.e. sth like

http://{base_url}/admin/structure/views/view/{view}/preview/{display}?page=1&_preview_args=filter1/filter2

in D7 the contextual filter is appended at the end of the URL, like

http://{base_url}/admin/structure/views/view/{view}/preview/{display}/filter1/filter2?page=1

manningpete’s picture

Issue tags: -Needs reroll

I could apply the patch, so no reroll is needed.

dawehner’s picture

Thank you for working on this issue!! I'm curious whether you have checked how it works in Drupal 7. I remember that it used to work,
maybe it used to be an easier solution ... but in general it seems pretty sane what the patch does.

--- /dev/null
+++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_contextual_filter_paging.yml

+++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_contextual_filter_paging.yml
@@ -0,0 +1,249 @@

@@ -0,0 +1,249 @@
+id: test_contextual_filter_paging

Just in case, I'd prefer to name it test_argument_paging, because this is still the internal technical term for it.

mondrake’s picture

StatusFileSize
new1.86 KB
new11.72 KB

I'd prefer to name it test_argument_paging

done.

As to why it worked in D7 and no longer in D8, I do not fully understand but I have just a feeling it is related to the changes in the routing system. The '$args' would be picked from the URL in D7 when paging through pager links, but AFAICS in D8 args appended to the URL won't because there's no matching route. So the patch here moves the $args to the URL query parameters which is not influencing the routing and can be treated separately.

Status: Needs review » Needs work

The last submitted patch, 25: 2066207-25.patch, failed testing.

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new7.12 KB
new14.03 KB

Trying to fix the failures related to the test view.

Status: Needs review » Needs work

The last submitted patch, 27: 2066207-27.patch, failed testing.

mondrake’s picture

StatusFileSize
new14.04 KB
new1.16 KB

Let's see this one.

mondrake’s picture

Status: Needs work » Needs review
mondrake’s picture

StatusFileSize
new3.34 KB
new16.46 KB

Looks like we may not need to push/pop the request in ViewUI::renderPreview anymore. I think that was relevant when that method was calling drupal_render() so that the pager could use a different 'current' request to build its links. But now, since #2412805: View preview does not attach assets provided by plugins, ViewUI::renderPreview returns a render array, so if we push a request and then pop it within the same method this ends up as a no-op, since the rendering occurs at a later stage.

Let's see what bot thinks of this.

mondrake queued 31: 2066207-31.patch for re-testing.

baisong queued 31: 2066207-31.patch for re-testing.

baisong’s picture

Triage notes:

  1. Summary is up-to-date.
  2. Bug is still present: Reproduced the issue on simplytest.me.
  3. No duplicate issues found.
  4. Beta evaluation added to summary.
xjm’s picture

(Saving proposed issue credit for discussion and triage participants at LA.)

dawehner queued 31: 2066207-31.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 31: 2066207-31.patch, failed testing.

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new16.49 KB

Plain reroll.

lendude’s picture

StatusFileSize
new16.54 KB

Didn't apply anymore, did a reroll.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Status: Needs review » Needs work

The last submitted patch, 39: 2066207-39.patch, failed testing.

lendude’s picture

Status: Needs work » Needs review
StatusFileSize
new16.57 KB

Reroll.

Status: Needs review » Needs work

The last submitted patch, 42: 2066207-42.patch, failed testing.

The last submitted patch, 42: 2066207-42.patch, failed testing.

vprocessor’s picture

Status: Needs work » Needs review

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Priority: Major » Normal

@xjm @alexpott @cilefen @dawehner and I agreed that this is not a major bug because it only affects the Views Preview UI, and only under certain circumstances (contextual filters and pager navigation).

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Anonymous’s picture

StatusFileSize
new12.18 KB
new16.56 KB

#42 works perfect!
#43, #44 looks like random fails.

Nit reroll. RTBC++

The last submitted patch, 51: 2066207-51-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Anonymous’s picture

Version: 8.5.x-dev » 8.6.x-dev
StatusFileSize
new2.64 KB
new16.85 KB

CS fixed.

borisson_’s picture

Status: Needs review » Needs work
+++ b/core/modules/views_ui/src/Tests/PreviewTest.php
@@ -239,6 +239,42 @@ public function testPreviewWithPagersUI() {
+    $this->drupalPostForm(NULL, $edit = [], t('Update preview'));
...
+    $this->drupalPostForm(NULL, $edit = ['view_args' => 'page'], t('Update preview'));

I don't think we need the t around these buttons as this view is not translated.
This is the only nitpick I could find, otherwise this patch looks very good.

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new16.88 KB
new1.42 KB

Fixes for #54 and array CS.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

#54 was addressed in #55 + array style improved! Thanks, RTBC.

Unfortunately, part of the API required for the test is in the WTB area, so the test also is WTB. But this new test is definitely not prevent the PreviewTest converting to JTB.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 55: 2066207-55.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Anonymous’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 55: 2066207-55.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

lendude’s picture

Almost ready I think

  1. +++ b/core/modules/views_ui/src/Tests/PreviewTest.php
    @@ -17,7 +17,14 @@ class PreviewTest extends UITestBase {
    +    'test_argument_paging'
    

    per codesniffer: missing a trailing comma

  2. +++ b/core/modules/views_ui/src/Tests/PreviewTest.php
    @@ -322,7 +365,7 @@ protected function getPreviewAJAX($view_name, $panel_id, $row_count) {
    -  protected function clickPreviewLinkAJAX($url, $row_count) {
    +  protected function clickPreviewLinkAJAX($url, $row_count = NULL) {
    
    @@ -335,7 +378,9 @@ protected function clickPreviewLinkAJAX($url, $row_count) {
    -    $this->assertPreviewAJAX($result, $row_count);
    +    if ($row_count) {
    +      $this->assertPreviewAJAX($result, $row_count);
    +    }
    

    Why are we changing this and not just adding a row count to the call? It wouldn't hurt to test that the pager works, right?

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new1.62 KB
new16.13 KB

Thanks @Lendude, addressed #60.

Status: Needs review » Needs work

The last submitted patch, 61: 2066207-61.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new16.47 KB
new1.64 KB

#61 fails because the test assumes the view's style is 'default' and not 'table'. Changed the test view.

Anonymous’s picture

StatusFileSize
new15.59 KB
new6.06 KB

#63: Nice catch!

Also I tried to import the view, and noticed that a couple of other fields also need to be updated. So, perhaps it makes sense to add more asserts and expand the test for both content types. Done.

Anonymous’s picture

#64: Found an out-of-date assert message (static word: "Page"):
$this->assertEqual(count($elements), 5, 'Expected items of "Page" type.');
It should be
$this->assertEqual(count($elements), 5, "Expected items of '$type' type.");
It will be fixed if the #64 receives your approval.

lendude’s picture

Status: Needs review » Needs work

Nice, more coverage!

  1. +++ b/core/modules/views_ui/src/Tests/PreviewTest.php
    @@ -266,20 +266,29 @@ public function testPreviewPagingWithContextualFilters() {
    +      // Set the contextual filter to show special content type.
    

    special? 'specific' I'd say.

  2. +++ b/core/modules/views_ui/src/Tests/PreviewTest.php
    @@ -266,20 +266,29 @@ public function testPreviewPagingWithContextualFilters() {
    +      // Check 2 pages after contextual filter settings.
    

    Check that there are two pages after setting the contextual filter.

  3. +++ b/core/modules/views_ui/src/Tests/PreviewTest.php
    @@ -266,20 +266,29 @@ public function testPreviewPagingWithContextualFilters() {
    +      $this->verbose($this->content);
    

    debug?

  4. +++ b/core/modules/views_ui/src/Tests/PreviewTest.php
    @@ -266,20 +266,29 @@ public function testPreviewPagingWithContextualFilters() {
    +      // Check that all results is expected type.
    

    Check that all results are of the expected type.

  5. +++ b/core/modules/views_ui/src/Tests/PreviewTest.php
    @@ -266,20 +266,29 @@ public function testPreviewPagingWithContextualFilters() {
    +      $this->assertEqual(count($elements), 5, 'Expected items of "Page" type.');
    

    Yeah use $type here. Also if we have 10 results, 5 page five article and the sorting is by type, this would still be true. So we'd need to test this on the first page of the result too if we want to be sure the filter worked.

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new15.9 KB
new2.46 KB

@Lendude, thank you! Done.

lendude’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

@vaplas, thanks, look good to me now. Updated the IS a bit to include the findings in #31 that seem relevant to the removal of a big section of code here.

lendude’s picture

Issue summary: View changes

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 67: 2066207-67.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Reviewed & tested by the community
catch’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/views_ui/src/Tests/PreviewTest.php
@@ -239,6 +246,52 @@ public function testPreviewWithPagersUI() {
+      $this->assertTrue(empty($this->xpath('//a[@title = :title]', [':title' => 'Go to page 3'])));

Shouldn't this have an assertFalse() for go to page 4 as well?

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

mondrake’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
megha_kundar’s picture

Status: Needs work » Needs review
StatusFileSize
new15.72 KB

Status: Needs review » Needs work

The last submitted patch, 79: 2066207-79.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

adityasingh’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new5 KB
new15.66 KB

Fixed deprecation code and coding standard.

Status: Needs review » Needs work

The last submitted patch, 81: 2066207-81.patch, failed testing. View results

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

griffynh’s picture

Hola, this came up in the #bugsmash channel as the Views daily triage target.

As we haven't had an update in over four years, if there's no update in the next three months, this issue may be closed.

maxilein’s picture

But it is such an annoyance that this functionality is missing ... for everyone who develops using views ...

johnv’s picture

Title: Contextual filters in view preview UI are not retained on preview navigation » Views UI preview does not retain Contextual filters on pagination
Issue summary: View changes
joelpittet’s picture

The tests look great, needs a re-roll of course but better to move this to a MR.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.