Page not found when a node is deleted via contextual filter

Created on 14 June 2019, about 5 years ago
Updated 22 February 2024, 4 months ago

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

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Render 

Last updated 1 day ago

Created by

🇮🇳India subhojit777

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs review about 1 year ago
  • Status changed to Needs work about 1 year ago
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
    +++ 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

  • Issue was unassigned.
Production build 0.69.0 2024