Cancel returns user to node preview

Created on 14 November 2023, about 1 year ago
  1. Start creating a node
  2. Preview node
  3. Return to the node creation form
  4. Hit 'Cancel'

You are returned to the node preview rather than the content overview or whatever path you'd configured.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇨🇦Canada mrogers

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

Comments & Activities

  • Issue created by @mrogers
  • 🇵🇱Poland ad0z

    It's module behavior due to the redirect back to the HTTP referer, when there is no form_state redirect, destination parameter or entity edit form. When you go back from preview page, HTTP referer is set to preview page.
    I agree it's unexpected behavior and should be considered as a bug.
    I think we should keep initial HTTP referer when entity is created and redirect user there.
    I've prepared patch which implement it. It was quite hard to store this information in tempstore.private with unique key as entity uuid change when node save submit is pressed and HTTP referer is not expected one anymore.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    2 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    2 pass
  • Status changed to Needs review about 1 year ago
  • 🇨🇦Canada mrogers

    Amazing, patch is working flawlessly on our site. Thank you @ad0z !

  • Status changed to Needs work 20 days ago
  • heddn Nicaragua
    +++ b/cancel_button.module
    @@ -131,7 +131,13 @@ function cancel_button_form_alter(&$form, FormStateInterface $form_state) {
    +        $uuid = $form_state->get('form_display') ? $form_state->get('form_display')->uuid() : NULL;
    

    Can we add some code comments about what this is doing and what it is protecting us against? This is pretty dense code and some explanation will go a long way to help future selves know what it is doing.

  • 🇮🇳India shivam_tiwari

    I am working on this.

  • 🇮🇳India shivam_tiwari

    @heddn I checked this issue and provided patch is also, but I am getting same issue on content add form. I tested in Drupal 11.0.9.
    I followed following steps:
    1. Enabled module and added redirect for node form.
    2. When I am going to add article, on add article node form I get content listing page URL on the cancel button. (/node/add/article)
    3. After filling out the form go to the preview page and get back, this cancel button URL is changed to preview page URL.
    Can you please suggest here what will be the correct URL at this time? It will be the (/node/add/article) or the URL that I set on configurations.
    cc @Maintainers

Production build 0.71.5 2024