Problem/Motivation

Issue: Currently if you create view block, that uses "Content ID from URL" contextual filter, it will work only when you are viewing a node. When the node is previewed - URL is using UUID, hence the view will won't work.

What is expected: "Content ID from URL" contextual filter must work event if UUID is used instead of ID. Other solution might be creating additional "Content UUID from URL" contextual filter.

Steps to reproduce

  1. Create 4 contents of any type
  2. Create a block view to display published nodes. Display only title of each node in view.
  3. Add a contextual filter for the ID. Select "Content ID from URL" as the default value for the filter
  4. Place the block in sidebar and view any page
  5. Block is visible with the title of the current node.
  6. Edit the same node and select 'Preview' button.
  7. Block is not visible in node preview

Proposed resolution

Update core/modules/node/src/Plugin/views/argument_default/Node.php to get node ID from node preview route.

Remaining tasks

Patch->Done
Add tests->Done
review
commit

User interface changes

None

API changes

None

Data model changes

none

Release notes snippet

Issue fork drupal-2978024

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

Elaman created an issue. See original summary.

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.

benjamin.merkley’s picture

Having the same issue.

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.

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.

esch’s picture

Having the same issue.

quietone’s picture

Component: node system » views.module
Issue summary: View changes
Issue tags: +Bug Smash Initiative

This is a fortnightly bug smash triage issue, adding tag. Moving to views so the views maintainers will see this (lendude commented in slack that they had not seen this issue).

Some minor updates to the IS.

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.

dan612’s picture

StatusFileSize
new639 bytes

I think this issue can be addressed in the Node module which provides the default argument to views. Patch attached.

harshil_jadav’s picture

Status: Active » Reviewed & tested by the community

This Patch #15 Looks Good, I have tested in my local and and it worked.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work

The Needs Review Queue Bot tested this issue.

While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

ameymudras’s picture

Tested #15 and it works absolutely as expected. Only thing that can be an improvement here is using an else if condition rather than if

dan612’s picture

Status: Needs work » Needs review
  • Opened a merge request per #17
  • changed to elseif as per #18
dan612’s picture

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs issue summary update

Issue summary still needs to be completed.

Also as a bug will need a test case showing the issue

Akhil Babu made their first commit to this issue’s fork.

akhil babu’s picture

Issue summary: View changes
akhil babu’s picture

Issue summary: View changes
akhil babu’s picture

Issue summary: View changes
akhil babu’s picture

Status: Needs work » Needs review

Added test and Updated issue summary

smustgrave’s picture

Status: Needs review » Needs work

Appears to be missing the fix though.

smustgrave’s picture

Status: Needs work » Needs review

Nope there it is.

arisen’s picture

StatusFileSize
new377.48 KB
new384.56 KB

Reviewed the MR 5764 and also applied the patch locally. The patch applies cleanly

Checking patch core/modules/node/src/Plugin/views/argument_default/Node.php...
Checking patch core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php...
Applied patch core/modules/node/src/Plugin/views/argument_default/Node.php cleanly.
Applied patch core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php cleanly.

Reviewed the issue as per the steps.
The issue gets resolved after applying the patch. i.e. Contextual filter(Content ID from URL) gets applied properly on the node preview page.
Attaching the screenshots.

The Assertions added in the Merge Request runs without any failures. RTBC for me.

smustgrave changed the visibility of the branch 2978024-test-only to hidden.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests, -Needs issue summary update +Needs Review Queue Initiative

@arisen post a screenshot of the patch applying it's needed or useful, we know it applies by the MR being green.

Opening a test only MR is unnecessary so it's hidden.

Running test-only feature of main MR.

1) Drupal\Tests\views\Functional\Plugin\ArgumentDefaultTest::testArgumentDefaultNode
Behat\Mink\Exception\ElementNotFoundException: Element matching xpath "//*[@id="block-view-block-id"]" not found.
/builds/issue/drupal-2978024/vendor/behat/mink/src/WebAssert.php:418
/builds/issue/drupal-2978024/vendor/behat/mink/src/WebAssert.php:457
/builds/issue/drupal-2978024/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php:176
/builds/issue/drupal-2978024/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
ERRORS!
Tests: 5, Assertions: 36, Errors: 1.

So removing tests tag.

Left a comment on the MR.

akhil babu’s picture

Status: Needs work » Needs review

Thanks for reviewing @dan612 and @smustgrave. I have updated the condition to

    $node = $this->routeMatch->getParameter('node') ?? $this->routeMatch->getParameter('node_preview');
    if ($node instanceof NodeInterface) {
      return $node->id();
    }

Moving back to needs review

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Believe this is now good.

quietone’s picture

Issue tags: +Usability

This issue is changing the UI so adding Usability tag, there should also be screenshots available for reviewers from the Issue Summary.

I then tested this using the steps in the issue summary. I created the problem and then applied the diff and reloaded the preview page. There was no change. After clearing cache the new block was displayed.

I ran the test locally without the fix and it failed as expected. I read the MR which looks fine to me. I also updated credit

Leaving at RTBC

lauriii made their first commit to this issue’s fork.

  • lauriii committed c3c9dd1e on 11.x
    Issue #2978024 by Akhil Babu, dan612, smustgrave, quietone, elaman,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed c3c9dd1 and pushed to 11.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.