-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spike: CMS Preview with Next.js #14419
Comments
There are old existing AP tickets that look at this problem. We may not need what the next.module provides for Preview; investigate whether the next.js entity types are required, or what else those modules provide. Does authentication matter? How does content build handle the authentication piece currently for preview? Is its solution a good one? |
@timcosgrove to link existing (old) tickets re: preview setup to this one. |
CMS PREVIEWI followed the steps here: https://next-drupal.org/learn/preview-mode CMS Preview Setup
Authenticationnext-drupal's OOTB preview functionality with auth is necessary. Authentication is required to view unpublished content revisions. Published pages do not require auth, the normal jsonapi routes render fine. Preview AppearanceWe can easily render a button that links to the preview environment. I added this code to a new file: <?php
namespace Drupal\va_gov_api\Plugin\Next\SitePreviewer;
use Drupal\Core\Entity\EntityInterface;
use Drupal\next\Plugin\SitePreviewerBase;
/**
* Provides a link to the preview page.
*
* @SitePreviewer(
* id = "link",
* label = "Link to preview",
* description = "Displays a link to the preview page."
* )
*/
class Link extends SitePreviewerBase {
/**
* {@inheritdoc}
*/
public function render(EntityInterface $entity, array $sites) {
$build = [];
foreach ($sites as $site) {
$build[] = [
'#type' => 'link',
'#title' => $this->t('Preview'),
'#url' => $site->getPreviewUrlForEntity($entity),
'#attributes' => [
'class' => ['button', 'button--primary', 'node-preview-button'],
'target' => '_blank',
],
];
}
return $build;
}
} Clear cache and visit In /**
* Alter the result of \Drupal\next\Plugin\SitePreviewerInterface::render.
*
* This hook is called after the preview has been assembled.
*
* @param array &$preview
* The preview renderable array from the site_previewer.
* @param array $context
* Context in which the entity is previewed with the following keys:
* - 'plugin': the site_previewer plugin.
* - 'entity': the entity in preview.
* - 'sites': the sites for this entity.
* - 'original_build': the original un-altered build.
*
* @ingroup next_api
*/
function va_gov_api_next_site_preview_alter(array &$preview, array $context) {
// Don't let next overwrite the existing node view page.
$preview['content'] = $context['original_build'][0]['content'];
// See va_gov_backend_preprocess_page() for existing preview button logic.
} The preview button that directs to a next.js site is only rendered if the content type is enabled to use next at There will need to be some cleanup / handling in Preview works whether running Per environment previewWe will need to create/update the next.js site config on a per-environment basis to ensure correct urls & secrets. next-build will likely need to be included in cms environment builds. AWS Secrets Manager is a good candidate to securely store the different environment secrets needed, private keys, etc |
Example PRs: next-build: department-of-veterans-affairs/next-build#162 |
This looks good. Very thorough! My only real thought is about |
Requirements
A CMS user should able to view their changes to a piece of content on-the-spot, even if they are not published yet, so that they know what their content will look like when viewed by a Veteran.
Acceptance Criteria
Description
As part of Next Build, each CMS instance will need a persistent Next.js instance that is responsible for rendering a single node on demand, to facilitate preview. This preview should be capable of rendering content that is in draft state as well as published content.
Next-Drupal provides guidance for how to configure a Next.js instance and a Drupal instance to coordinate to do preview: https://next-drupal.org/learn/preview-mode
This investigation should
Note that for this effort, we are not looking to make changes to the UX; the Content Build preview button should be replaced by a button that previews the page with Next, for those pages that are Next.js enabled.
Please see this ticket for an example functional use case that needs to be handled re: unpublished content: #12792
Looking at how we use Next.js to accomplish this will be part of the ticket. Will we build static, or will we use a persistent preview server? Are there conflicts between our configuration for static build and having a persistent preview server.
Team
Please check the team(s) that will do this work.
CMS Team
Public Websites
Facilities
User support
Accelerated Publishing
The text was updated successfully, but these errors were encountered: