Problem/Motivation

Steps to replicate:

1. Create a node
2. Go to the node's full view page, say /node/1
3. Expand the contextual filter, and click Delete
4. Confirm the deletion process in the confirmation screen
5. You will see page not found error

The contextual filter takes the current path as destination which causes the problem.

Proposed resolution

1. Disable delete operation in the contextual filter in node's full view page

I don't like approach 1 though, because it is very much specific about the type of operation.

Remaining tasks

TBD

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

TBD

Comments

subhojit777 created an issue. See original summary.

subhojit777’s picture

Issue tags: +#DCD19
sumit-k’s picture

Assigned: Unassigned » sumit-k
rkostov’s picture

'destination' parameter comes from function initContextual() in file core/modules/contextual/js/contextual.js

    var destination = 'destination=' + Drupal.encodePath(Drupal.url(drupalSettings.path.currentPath));
    $contextual.find('.contextual-links a').each(function () {
      var url = this.getAttribute('href');
      var glue = url.indexOf('?') === -1 ? '?' : '&';
      this.setAttribute('href', url + glue + destination);
    });

my approach to solve this problem is by skipping the 'destination' parameter for links with pattern 'node/%/delete'

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

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

sumit-k’s picture

Patch works for me.

sumit-k’s picture

Status: Active » Needs review

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
ranjith_kumar_k_u’s picture

StatusFileSize
new1.45 KB

Re-rolled #4 for 9.4

ambikahirode’s picture

#11 working for me on local 9.4.Tested and Verified.refer Screenshot.

ambikahirode’s picture

StatusFileSize
new79.67 KB
new128.9 KB

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative, +Needs tests

I can confirm this issue still exists in 10.1

This will need some tests to make sure it's fixed.

_utsavsharma’s picture

StatusFileSize
new718 bytes

Rerolled for 10.1.x.
But the issue on #15 still needs to be addressed.

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

ranjith_kumar_k_u’s picture

StatusFileSize
new952 bytes
new1.63 KB
ranjith_kumar_k_u’s picture

StatusFileSize
new788 bytes
ranjith_kumar_k_u’s picture

Status: Needs work » Needs review
larowlan’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests
+++ b/core/modules/node/tests/src/FunctionalJavascript/ContextualLinksTest.php
@@ -106,6 +106,10 @@ public function testRevisionContextualLinks() {
+    // Confirm that the "Delete" contextual link doesn't contain
+    // the destination parameter.
+    $this->assertStringNotContainsString('?destination=', $links[1]->getAttribute('href'));

I think we can use built in PHP APIs to be a bit more precise here.

Something like this

$query = parse_url($links[1]->getAttribute('href'), PHP_URL_QUERY);
parse_str($query, $parsed_query);
$this->assertArrayNotHasKey('destination', $parsed_query);
+++ b/core/modules/contextual/js/contextual.js
@@ -104,7 +104,12 @@
+      if (url.match(/(node\/\d+\/delete$|node\/\d+\/delete\?.+$)/g) === null) {
+        this.setAttribute('href', url + glue + destination);
+      } else {
+        this.setAttribute('href', url);
+      }

Unfortunately, we can't hardcode node specific logic in contextual module.

What happens if another module has a delete contextual link (e.g. media) and we want similar logic.

So I think we need to go back to the drawing board here.

We need an API to allow an individual link to override its destination.

Firstly, I think we replace the string based concatenation of URL params in contextual.js with UrlSearchParams which is now available in D10 because we don't support IE anymore.

Then I think we should check if the destination is already set before we blindly add it.

Then I think the node contextual link should declare 'options' for the delete plugin, which would be ['query' => ['destination' => '/']]

Something like that anyway. We might take a few iterations to get to a workable API

Version: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

sumit-k’s picture

Assigned: sumit-k » Unassigned

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.

mortona2k’s picture