Problem/Motivation

When editing a View with a Page display, if the Path is changed in the settings, the change is not reflected in the Preview pane despite Auto preview being checked.
(The display's name and path are displayed below the result, at the bottom of the page)
You must save the view before, only then the setting is used.

Steps to reproduce

  1. Create or edit a view with page display
  2. Make sure auto preview is enabled
  3. Update the page path more than once
  4. Notice the path changes are not shown in the preview

Proposed resolution

Show the latest Path in the preview.

Remaining tasks

  1. Create patch
  2. Review patch
  3. Commit patch

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#55 2620134_2.png34.97 KBjaydev bhatt
#55 2620134_1.png22.54 KBjaydev bhatt
#46 interdiff-2620134-44-46.txt950 bytesvakulrai
#46 updated_views_preview-2620134-46.patch4.73 KBvakulrai
#44 interdiff-2620134-37-44.txt3.71 KBmohit_aghera
#44 views_ui_preview_path_update-2620134-44.patch3.81 KBmohit_aghera
#41 Afetr-patch.png77.4 KBmitthukumawat
#41 Before-patch.png69.42 KBmitthukumawat
#37 interdiff-2620134-34-37.txt1.2 KBmohit_aghera
#37 views_ui_preview_path_update-2620134-37.patch4.35 KBmohit_aghera
#35 plain_link.png12.2 KBguilhermevp
#34 interdiff-2620134-29-34.txt2.51 KBmohit_aghera
#34 views_ui_preview_path_update-2620134-34.patch4.3 KBmohit_aghera
#32 2620134-after_patch.png140.62 KBabhijith s
#32 2620134-before_patch.png55.84 KBabhijith s
#31 Test-1.png13.85 KBguilhermevp
#29 Watchdog__Log_entries____Site-Install.png29.09 KBmohit_aghera
#29 interdiff-2620134-19-29.txt1.46 KBmohit_aghera
#29 views_ui_preview_path_update-2620134-29.patch2.79 KBmohit_aghera
#25 Screen Shot 2020-10-02 at 2.35.46 pm.png10.17 KBlarowlan
#25 Screen Shot 2020-10-02 at 2.35.37 pm.png4.77 KBlarowlan
#25 Screen Shot 2020-10-02 at 2.35.34 pm.png26.13 KBlarowlan
#25 Screen Shot 2020-10-02 at 2.35.31 pm.png9.08 KBlarowlan
#24 AfterPathUpdate_After_PatchApplied.png324.84 KBjanmejaig
#24 BeforePathUpdate_AfterPatchApplied.png323.93 KBjanmejaig
#23 views_path.gif1.98 MBbranjansse
#21 Screen Shot 2020-08-16 at 4.16.23 PM.png78.48 KBkristen pol
#21 Screen Shot 2020-08-16 at 4.16.12 PM.png79.73 KBkristen pol
#19 interdiff_15-19.txt1.34 KBbranjansse
#19 views_ui_preview_path_update-2620134-19.patch1.53 KBbranjansse
#15 views_ui_preview_path_update-2620134-15.patch902 bytesbranjansse
#13 Screen Shot 2020-08-05 at 11.38.08 AM.png75.29 KBkristen pol
#13 Screen Shot 2020-08-05 at 11.37.56 AM.png79.12 KBkristen pol
Screen Shot 2015-11-20 at 12.11.48 PM.png41.96 KBAnonymous (not verified)

Issue fork drupal-2620134

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Anonymous’s picture

JKerschner created an issue. See original summary.

Anonymous’s picture

Issue summary: View changes
Anonymous’s picture

Title: Preview path doesn't update when changing path setting » Views preview path doesn't update when changing path setting
Version: 8.0.0 » 8.1.x-dev

Just confirmed that this bug still exists.

Anonymous’s picture

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

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

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now 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.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now 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.

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.

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.

kristen pol’s picture

Priority: Normal » Minor
Issue tags: +Bug Smash Initiative
StatusFileSize
new79.12 KB
new75.29 KB

Confirmed this is still a bug.

branjansse’s picture

Thanks for confirming @Kristen Pol. I am working on this and get back soon with resolution.

branjansse’s picture

StatusFileSize
new902 bytes

Please review the patch. Now the path url is getting from the views display handler path. Previously it was coming from views url. Please let me know if the approach not correct.

kristen pol’s picture

Status: Active » Needs work

Thanks for the patch. Tests fail so changing to needs work.

branjansse’s picture

I am working on the fix for the test case failure.

kristen pol’s picture

Thanks. I see that this is two lines but could be one. Is there some reason you split this?

+++ b/core/modules/views_ui/src/ViewUI.php
@@ -562,7 +563,8 @@ public function renderPreview($display_id, $args = []) {
+        $url = Url::fromUserInput('/' . $executable->display_handler->getOption('path'));
+        $path = $url;

Could change to:

$path = Url::fromUserInput('/' . $executable->display_handler->getOption('path'));

branjansse’s picture

Status: Needs work » Needs review
StatusFileSize
new1.53 KB
new1.34 KB

Please review the patch.
@kristen-pol Thanks for the suggestion we can do that in single line. For better readability i have done that in two lines but we can merge those 2 lines into 1.

kristen pol’s picture

Issue tags: +DCCO2020

Reviewing this for DrupalCamp Colorado contribution day.

kristen pol’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new79.73 KB
new78.48 KB

Thanks for the update. Marking RTBC since:

1) Patch still applies cleanly to 9.1.x.

2) Tests pass and I'm making the assumption that additional tests aren't needed.

3) Changes are straight forward and address the issue in the issue summary.

4) Title and issue summary are clear.

5) Passes manual review. See screenshots.

6) Note: updated issue summary to use template and filled in some information.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs manual testing, +Needs tests

$executable->getUrl() does a lot more than display the path, it has argument parsing etc.

Are we losing that functionality if we make this change?

Can we manually test previewing a view with contextual filters, and arguments entered into the preview form before and after this patch and ascertain if there is a change in behaviour.

And if so, that indicates we don't have tests, which also indicates we should at least be adding some here.

Tagging for both those tasks.

branjansse’s picture

StatusFileSize
new1.98 MB

Thanks @larowlan for your review. Since no one has picked this for manual testing let me explain the patch.

Here i have not changed how $executable->getUrl() is working, i just changed the $path variable that picks the current views path and display that on Update Preview button click.

This feature is covered by the test case also.
Also i have made small GIF as per your comment using contextual filter. Please let me know if i am taking thing other way what you have suggested.

janmejaig’s picture

I have checked this issue and found that it is working fine for D 9.1.x after applying #19 patch & Please find the screen shot attached for the same below . Following are the steps done to test & verify the same :

Steps to Test

  1. Create or edit a view with page display
  2. Make sure auto preview is enabled
  3. Apply the patch
  4. Update the page path more than once (observe the path before update )
  5. Notice the path changes are shown in the preview (observe the path after update )
larowlan’s picture

Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new9.08 KB
new26.13 KB
new4.77 KB
new10.17 KB

I tested this manually, and I think it should be closed (works as designed) - here's my reasoning

  • The preview outputs the path as a link
  • When you edit the path, the view is not yet saved
  • So Drupal's routes have not yet been updated to reflect the new view path
  • So with the current patch, we immediately update the link in the preview
  • But clicking this link yields a Page Not Found, because the view has not been saved, and therefore Drupal's routes have not yet been updated
  • In HEAD, when you save the view, the link is updated. But not beforehand, because the link has nowhere to link to yet.

I will seek a second opinion from others in the Bug Smash Initiative

pameeela’s picture

I initially agreed with #25 but noticed two things:

  1. 'View Page' button in the top right updates before the view is saved, so this already links to a 404
  2. 'Title' of the view in the preview section updates before the view is saved

So I guess that updating the path in the preview at least makes it consistent with the rest of the behaviour. The fact that we know it's going to be a broken link is kind of odd but there already is one in the button.

lendude’s picture

Tried to form an opinion about this one but ¯\_(ツ)_/¯

The fact that we know it's going to be a broken link is kind of odd but there already is one in the button.

So, I think if we update this to the current route, we would need to check if the Url is valid before outputting it as a link.

Or we can go a different route and check if $executable->getUrl() !== $executable->display_handler->getOption('path') and then output a different text in te preview, something like:
[link-to-not-updated-patg] (will be [new-path] after saving the View)

I don't know, the text could probably be better, but hopefully you get my point.

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.

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new2.79 KB
new1.46 KB
new29.09 KB

I tried to display both the URLs in list to see how it looks like.
I've updated the patch to review it.

This is how it looks in backend:
Dblog view

I think we can also ask someone from the usability team to get a better understanding.

kristen pol’s picture

Regarding #27, IMO I think outputting the path as plain text instead of a link is fine, since as noted in #25, the page doesn't exist yet because the view hasn't been saved. I feel like this is a bug or, at least, a UX issue. I would expect the path to show up properly in the preview, or not show at all.

guilhermevp’s picture

StatusFileSize
new13.85 KB

Patch #29 seems to be a move in the right direction, however, as it is in my testing, the View Page still returns a page not found. AS #25 pointed out, Title updates before being saved, so I belive both should behave in the same way, both or none should update before saved, personally I beleive none should, as it feels more intuitive to apply changes through a save button. The new path after view is saved should be only a preview string, because as it is it also leads to a page not found.

abhijith s’s picture

StatusFileSize
new55.84 KB
new140.62 KB

Applied patch #29 and it worked fine.Adding screenshots below.

Before patch:
before

After patch:
after

RTBC +1

kristen pol’s picture

Status: Needs review » Needs work

I like these new approach of showing both, but IMO I think the "New path after view is saved" path should not be linked because that page doesn't necessarily exist. So, for consistency, IMO I would argue that the link could be left out for *both* of these. Or like mentioned in #27 and #31, at minimum check if the path exists before linking it. IMO I think it's preferable just not linking them. The linked pages will usually be an old version of the view, so IMO having the link doesn't really add value and might even cause confusion.

mohit_aghera’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new4.3 KB
new2.51 KB

- Update code to display plain url for the new URL so it is not clickable.
- Added small test case to ensure that URL is visible along with label.

guilhermevp’s picture

Issue tags: -Needs manual testing
StatusFileSize
new12.2 KB

Tested new patch, seems good to go!

The preview generates a plain preview, and the there is no way to access paths that doesn't exist. The preview button only updates when the changes are saved.
Will wait for the test to end to move to RTBC.

plain lin

Status: Needs review » Needs work

The last submitted patch, 34: views_ui_preview_path_update-2620134-34.patch, failed testing. View results

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new4.35 KB
new1.2 KB

Test cases seem to be passing on local.
It might be the case that as test cases are running inside the separate directory, path might be incorrect.
I've refactored test cases to ensure that we assert label and URL seperately.
Let's see how it goes.

guilhermevp’s picture

Status: Needs review » Reviewed & tested by the community

As I stated in the comment #35, now seems good to go.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/views_ui/src/ViewUI.php
@@ -697,7 +698,22 @@ public function renderPreview($display_id, $args = []) {
             if (isset($path)) {
...
+              if ($current_path->getGeneratedLink() !== $updated_path) {
...
+              else {
...
             else {

we've got some nested if/else going on here.

I think this would be easier to maintain if we split this off into a new method, e.g getPreviewPath or similar, that way we could reduce a lot of the nesting with early returns.

  1. +++ b/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_field.yml
    @@ -81,7 +81,7 @@ display:
    -      path: test/serialize/field
    +      path: /test/serialize/field
    

    Why was this change needed? I can't see any mention of it in the issue.

  2. +++ b/core/modules/views_ui/src/ViewUI.php
    @@ -562,7 +563,7 @@ public function renderPreview($display_id, $args = []) {
    -        $path = $executable->getUrl();
    +        $path = Url::fromUserInput('/' . $executable->display_handler->getOption('path'));
    

    Why did we need this change? See my comment above:

    $executable->getUrl() does a lot more than display the path, it has argument parsing etc.

    Are we losing that functionality if we make this change?

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.

mitthukumawat’s picture

StatusFileSize
new69.42 KB
new77.4 KB

Patch #37 applied successfully in drupal 9.3.x-dev version and the view path getting updated immediately. The path did not previewed as a link. Adding screenshots for reference.

kristen pol’s picture

Moving back to needs work based on #39.

Also, from #41, it looks like there is no space after the ":" and before the "/" so that should be added when the patch is updated.

kristen pol’s picture

Status: Needs review » Needs work
mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new3.81 KB
new3.71 KB

Fixing @larowlan's comments from #39
- I think, yml file change was unnecessary so I've removed it.
- Refactored the logic in a separate method, test cases are passing now.
- The $path variable is not overridden anymore. I think it is safer now.

Included @Kristen Pol's suggestion from #42 as well.

Status: Needs review » Needs work

The last submitted patch, 44: views_ui_preview_path_update-2620134-44.patch, failed testing. View results

vakulrai’s picture

Status: Needs work » Needs review
StatusFileSize
new4.73 KB
new950 bytes

@mohit_aghera , updated view configuration as tests are failing without these configs.

Status: Needs review » Needs work

The last submitted patch, 46: updated_views_preview-2620134-46.patch, failed testing. View results

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.

johnv’s picture

Title: Views preview path doesn't update when changing path setting » Views UI preview does not respect changed 'path' option until saving
Issue summary: View changes
jaydev bhatt’s picture

Assigned: Unassigned » jaydev bhatt

i'm working on this.

jaydev bhatt’s picture

Assigned: jaydev bhatt » Unassigned
Status: Needs work » Needs review
StatusFileSize
new22.54 KB
new34.97 KB

I have tested the patch, and it works with Drupal 11.1.1. I’ve also updated the patch to align with the latest codebase, as the original was created 4 years ago.

Additionally, I have resolved all PHPCS and JavaScript linting issues. However, I’m encountering PHPStan errors related to missing return types.

Locally, all level 1 issues appear to be fixed, but the CI pipeline still fails due to return type errors. Despite updating all methods in the ViewUI file, the number of reported issues has increased.

I need guidance on resolving this discrepancy between local and pipeline results. Marking this as NR.

smustgrave’s picture

Status: Needs review » Needs work

The view changes almost seem out of scope but the baseline would need to be regenerated

mohit_aghera’s picture

Fixed all the phpstan issues.
Resolved merge conflicts and removed changes related to views as this wasn't necessary.
There is one more failure in the CI, I'm going through that.

I've hidden the patches in favor of MR approach.

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.