Problem/Motivation
The "Preview" functionality does not work on forward revisions. The following error gets thrown:
Uncaught PHP Exception Symfony\\Component\\Routing\\Exception\\InvalidParameterException: "Parameter "node_revision" for route "entity.node.revision" must match "[^/]++" ("" given) to generate a corresponding URL." at .../docroot/core/lib/Drupal/Core/Routing/UrlGenerator.php line 199, referer: http://localhost/node/5/edit
Steps to Reproduce
While this error applies to any module that creates forward revisions, it was noticed in Workbench Moderation and for convenience I will write steps using that module.
Here are steps to reproduce using Workbench Moderation:
- Install and enable Workbench Moderation (tag 8.x-1.0-beta1 OR branch 8.x-1.x)
- Make a content type moderated, with all moderation states checked, and default moderation state as "Draft"
- Create a node for that type and click "Save and Create New Draft"
- Edit it and click "Save and Create New Draft"
- Edit it again and click "Preview"
- You will see the error described above
You can also create this error after publishing the node, creating a forward revision, and then previewing the forward revision.
Recommended Solution
Remove the generation of HTML head links in the NodePreviewController.
Comments
Comment #2
josephdpurcell commentedI can reproduce this issue. Updating the description with steps to reproduce. Also setting to Major.
Comment #3
josephdpurcell commentedI've confirmed this is also an issue with the latest code, 8.x-1.x branch.
Comment #4
josephdpurcell commentedAfter investigation, it appears the error is due to core not handling previews for forward revisions. Updating the description to clarify what is happening and moving to core.
I have added a recommended solution to remove the generation of HTML meta information on the preview page. It is a straightforward solution with low impact: the HTML meta information is likely superfluous given the previewed content does not yet exist.
Comment #5
josephdpurcell commentedUpdating title to be more relevant. And pointing to relevant code:
Here is the method that is setting the "node_revision" URL parameter to null: Drupal\Core\Entity\Entity::urlRouteParameters($rel). The relevant lines are:
Since the entity doesn't yet exist,
$this->getRevisionId()returns null, and since the "entity.node.revision" route does not allow the "node_revision" path segment to be null, the route generation fails.Comment #6
larowlanFix attached
Comment #8
jibranAnother WB bug moved to core #2708735: Creating a draft removes published node from taxonomy view.
Comment #9
shell_cm commentedI am looking at this issue to replicate.
Comment #10
shell_cm commentedI am unable to reproduce this using 8.2x drupal and 8.x-1.0+2-dev version of workbench moderation. Very possible I'm missing something...?
Comment #11
rooby commentedI have this problem on Drupal 8.1.1 and Workbench Moderation 8.x-1.0 and the patch in #6 seems to fix it.
Comment #12
amateescu commentedDiscussed this issue with @dawehner and we agreed that outputting link templates when previewing a node doesn't make any sense, so we should simply remove that code.
Also added a test for this. Since we can not get in this situation through the current core UI, the test just uses API calls.
Comment #14
dawehnerCan you please create a dedicated kernel test? We want to get rid of executing php code in our tests.
Comment #15
amateescu commented@dawehner, the reason I kept the test there even if it's doing only API calls is that at some point we'll be able to test this in the UI, for example when #2725533: Add experimental content_moderation module lands.
How about I add a @todo to change the code to use the UI when we're able to create forward revisions in core?
Comment #16
dawehnerThis otherwise trows an exception. Let's use a try catch +
$this->fail()Comment #17
amateescu commentedImproved the comments in the test a bit and added the @todo.
Comment #18
amateescu commentedDiscussed this on IRC but I'll post here for everyone else: the
try / catchpattern is for cases when we expect to get an exception, which is not the case here.Comment #19
dawehnerYou are right. Thank you @amateescu
Comment #20
alexpottCommitted cd87bb1 and pushed to 8.1.x and 8.2.x. Thanks!
Comment #23
tstoecklerYay, thanks for this. Closing #2751501: NodePreviewController should not render entity links in the HTML head as a duplicate.
Comment #24
tstoeckler