Preview does not work if the "node add" form isn't at its canonical URL

Created on 16 July 2018, almost 7 years ago
Updated 19 March 2025, 2 months ago

Problem/Motivation

We are using the Group module in one of our client projects. From it's project page:

The Group module allows you to create arbitrary collections of your content and users on your site and grant access control permissions on those collections

The module introduces some entities:

  • Group
  • Group content - This is used to relate a node or a user with the Group.

A node can be created as a part of the group and the URI to create node is at:

/group/{group_id}/content/create/group_node:{content_type}

It shows up the same node create form. However, the preview button has to be hidden in the module as it doesn't work well with the workflow of the module. Check Node previews don't work when adding group node Needs work

Same happens when editing content, with empty field on clicking "Preview" and going back to the canonical node edit form.

This brings the question: What if the node add/edit form is hosted on a different Route/URL other than the canonical one? Wouldn't preview work at all?

Proposed resolution

Use Symfony\Component\HttpFoundation\RequestStack to get the referer of the previous page from the HTTP request headers on Drupal\node\Form\NodePreviewForm and redirect the user to that when clicked on "Back to content editing". This mostly affects the new nodes.

Remaining tasks

Test and review the patch.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Postponed: needs info

Version

11.0 🔥

Component

node system

Created by

🇮🇳India ajits India

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.

  • 🇦🇺Australia acbramley

    Is this still relevant? The "Back to content editing" link uses Url::fromRoute (or node->toUrl()) to generate the URL so if Group is correctly modifying things at the route level then it should work as is?

  • Status changed to Closed: won't fix 3 days ago
  • 🇦🇺Australia acbramley

    I've manually reproduced this issue and looked into how group (or more explicitly the gnode) module works with these routes as well as skimmed through Node previews don't work when adding group node Needs work .

    From what I can see, gnode implements its own routes and forms to achieve this functionality and therefore should be in charge of altering the url for the back link.

Production build 0.71.5 2024