next-drupal
next-drupal copied to clipboard
Preview with moderated content / node revisions not working
Our Drupal setup is using content moderation and we noticed that draft versions of node cannot be viewed the same as unpublished content. We also noticed that node revisions (used by content moderation) in general cannot be viewed with the nextjs preview feature. Is there any way to make it work?
Sure. Node revisions are supported by default (except for nodes with paragraphs).
What happens when you visit the revision page? Do you see the working-copy
or an error page?
Thank you for the quick reply.
I have nothing I can show but I can try to explain. There is no error. The view page of the draft content just doesn’t show the iFrame preview with the nextjs render. It just shows the default drupal view.
So, yes, i see the working copy but not as a nextjs Preview.
The iframe preview is there for the published node?
Ah I found the issue. I'll push a fix. Hold on.
I pushed a fix. Can you try the latest dev version and let us know?
composer require 'drupal/next:1.0.x-dev@dev'
Thank you
(Didn't mean to close this)
I just tried it and it did not change. Also, the initial draft does have a preview but it 404s. Once it published it works. When creating another draft version, the preview defaults to the drupal built-in view (see screenshot).
What's the path for latest version?
node/6/latest
Looking into it.
OK I found the issue and pushed a fix for it. Can you try the latest dev and let me know?
composer require 'drupal/next:1.0.x-dev@dev'
Thanks! It fixed part of it. Now it shows the nextjs preview but it renders the latest published version not the latest revision (draft).
Hmm probably something with latest-version
and working-copy
. I tested this locally with a published revision and a draft latest revision. I had to go back to the docs to check this one.
These are the lines handling this:
https://github.com/chapter-three/next-drupal/blob/222295ac1f6577ed376dd87e183f9a3b65a59cb8/modules/next/src/Entity/NextSite.php#L151-L169
Can you swap line 157
and 167
and see if this fixes it?
Thanks for your help figuring this out.
Swapped the lines, but it didn't change anything. Sorry! It still always shows the published version.
hmm, can you temporarily disable preview mode for this entity type and check if you see the expected version?
How do I disable Preview mode?
I figured out a way to disable it. “View” and “Latest version” show the correct content.
Edit: When I create a new Page as draft that never had a published version and re-enable preview mode, the preview 404s.
Here's what I have:
https://user-images.githubusercontent.com/124599/152150761-967aa473-2b3f-4d22-998a-62e8457d510b.mp4
Yeah, looks perfect on your end. Is there anything special I have to do on the nextjs server? I am just using the drupal starter template.
Nothing special on the Next.js site. Here's the file
https://github.com/chapter-three/next-drupal/blob/cd2ed5c86e23c8c5c364e6094a93033cb955edc0/examples/example-marketing/pages/%5B%5B...slug%5D%5D.tsx#L62-L127
On the Drupal side, I've enabled content_moderation and added Basic Page
to the Editorial workflow.
Tried pretty much everything, but I cannot get it to work with the basic starter kit/app. Thank you very much for your time and effort.
We just made a last ditch effort and setup a new Drupal (patches applied) installation and Nextjs-app (your basic starter kit). Unfortunately, the outcome did not change. Revisions are not rendered. Only the latest default/published revision is being rendered.
Again, thank you very much for trying to help us. We would love to give this another shot in the future.
Please let me know if you need more information from our side, in case you want to look into this issue again at some point.
Edit: You can close this if your like.
Sure. I'm going to see if I can reproduce the issue with the basic starter today.
@senguendk Yep you were right. I updated the code in the basic starter to handle revision. Check it out.
export async function getStaticPaths(context): Promise<GetStaticPathsResult> {
return {
paths: await getPathsFromContext(["node--article", "node--page"], context),
fallback: "blocking",
}
}
export async function getStaticProps(
context
): Promise<GetStaticPropsResult<NodePageProps>> {
const path = await translatePathFromContext(context)
if (!path) {
return {
notFound: true,
}
}
// Check for redirect
if (path.redirect?.length) {
const [redirect] = path.redirect
return {
redirect: {
destination: redirect.to,
permanent: redirect.status === "301",
},
}
}
const type = path.jsonapi.resourceName
let params = {}
if (type === "node--article") {
params = {
include: "field_image,uid",
}
}
const node = await getResourceFromContext<DrupalNode>(type, context, {
params,
})
if (!node || (!context.preview && node?.status === false)) {
return {
notFound: true,
}
}
return {
props: {
preview: context.preview || false,
node,
},
revalidate: 900,
}
}
And add import { translatePathFromContext } from "next-drupal"
Can you replace the code in your [...slug].tsx
and let me know?
Thank you.
Thank you for responding so fast. We replaced the code, cleared .next and drupal cache. It did not make a difference unfortunately. It is, as if the "resourceVersion" or "rel" parameters are being ignored. We think so, because if the initial version of a page is a draft (unpublished), it 404s.
That's unfortunate. You reverted the change we made earlier to NextSite.php
right?
I'm going to pull a fresh Drupal copy and see if I can reproduce this.
Yes, we did. I also set up a clean drupal installation myself.
Let me know how it goes. Maybe we are still doing something wrong.
@senguendk Have you been able to look into this again?
@j4-m has been able to successfully preview revisions with content moderation with the latest dev release.
See https://github.com/chapter-three/next-drupal/issues/95#issuecomment-1043161140
@shadcn thanks for checking in again. Installed the latest dev release. Did not work unfortunately. Still the same issue.