Skip to content

Commit

Permalink
feat(next): update Next.js settings to add draft mode
Browse files Browse the repository at this point in the history
Issue #502
  • Loading branch information
JohnAlbin committed Jan 29, 2024
1 parent e0fc4bd commit a307486
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion modules/next/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drupal/next",
"description": "Next.js + Drupal for Incremental Static Regeneration and Preview mode.",
"description": "Next.js + Drupal for Incremental Static Regeneration and Draft mode.",
"type": "drupal-module",
"homepage": "http://drupal.org/project/next",
"license": "GPL-2.0-or-later",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public function defaultConfiguration() {
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['secret_expiration'] = [
'#title' => $this->t('Preview secret expiration time'),
'#description' => $this->t('The value, in seconds, to be used as expiration time for the preview secret. <strong>It is recommended to use short-lived secrets for increased security.</strong>'),
'#title' => $this->t('Secret expiration time'),
'#description' => $this->t('The value, in seconds, to be used as expiration time for the validation secret. <strong>It is recommended to use short-lived secrets for increased security.</strong>'),
'#type' => 'number',
'#required' => TRUE,
'#default_value' => $this->configuration['secret_expiration'],
Expand Down
2 changes: 1 addition & 1 deletion modules/next/next.info.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Next.js
description: Next.js + Drupal for Incremental Static Regeneration and Preview mode.
description: Next.js + Drupal for Incremental Static Regeneration and Draft mode.
type: module
core_version_requirement: ^9 || ^10
package: Web services
Expand Down
2 changes: 1 addition & 1 deletion modules/next/src/Controller/NextSiteEntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function environmentVariables(NextSiteInterface $next_site) {

if ($secret = $next_site->getPreviewSecret()) {
$variables += [
'preview_variables' => '# Required for Preview Mode',
'preview_variables' => '# Required for Draft Mode',
'DRUPAL_PREVIEW_SECRET' => $secret,
];
}
Expand Down
16 changes: 8 additions & 8 deletions modules/next/src/Form/NextEntityTypeConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ public function form(array $form, FormStateInterface $form_state) {
'#title' => $this->t('Settings'),
];

$form['preview_mode'] = [
'#title' => $this->t('Preview Mode'),
'#description' => $this->t('Configure preview mode the entity type.'),
$form['draft_mode'] = [
'#title' => $this->t('Draft Mode'),
'#description' => $this->t('Configure draft mode for this entity type.'),
'#type' => 'details',
'#group' => 'settings',
];

$form['preview_mode']['site_resolver'] = [
$form['draft_mode']['site_resolver'] = [
'#title' => $this->t('Plugin'),
'#description' => $this->t('Select a plugin to use for resolving the preview site for this entity type.'),
'#description' => $this->t('Select a plugin to use when validating the draft url for this entity type.'),
'#type' => 'select',
'#options' => array_merge(['' => $this->t('None')], array_column($this->siteResolverManager->getDefinitions(), 'label', 'id')),
'#default_value' => $entity->getSiteResolver() ? $entity->getSiteResolver()->getId() : NULL,
Expand All @@ -142,7 +142,7 @@ public function form(array $form, FormStateInterface $form_state) {
],
];

$form['preview_mode']['site_resolver_settings_container'] = [
$form['draft_mode']['site_resolver_settings_container'] = [
'#type' => 'container',
'#prefix' => '<div id="site-resolver-settings">',
'#suffix' => '</div>',
Expand All @@ -152,7 +152,7 @@ public function form(array $form, FormStateInterface $form_state) {
if ($site_resolver instanceof ConfigurableSiteResolverInterface) {
$form['configuration'] = [];
$subform_state = SubformState::createForSubform($form['configuration'], $form, $form_state);
$form['preview_mode']['site_resolver_settings_container']['configuration'] = $site_resolver->buildConfigurationForm($form['configuration'], $subform_state);
$form['draft_mode']['site_resolver_settings_container']['configuration'] = $site_resolver->buildConfigurationForm($form['configuration'], $subform_state);
}

$form['revalidation'] = [
Expand Down Expand Up @@ -223,7 +223,7 @@ public function submitSiteResolver(array $form, FormStateInterface $form_state)
* Handles switching the site resolver selector.
*/
public function ajaxReplaceSiteResolverSettingsForm($form, FormStateInterface $form_state) {
return $form['preview_mode']['site_resolver_settings_container'];
return $form['draft_mode']['site_resolver_settings_container'];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions modules/next/src/Form/NextSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
];

$form['preview_url_generator_container'] = [
'#title' => $this->t('Preview URL'),
'#title' => $this->t('Draft Mode'),
'#type' => 'details',
'#group' => 'settings',
];

$form['preview_url_generator_container']['preview_url_generator'] = [
'#title' => $this->t('Plugin'),
'#description' => $this->t('Select a plugin to use for the preview URL generator.'),
'#description' => $this->t('Select a plugin to use for the draft validation generator.'),
'#type' => 'select',
'#options' => array_column($this->previewUrlGeneratorManager->getDefinitions(), 'label', 'id'),
'#default_value' => $config->get('preview_url_generator'),
Expand Down
16 changes: 8 additions & 8 deletions modules/next/src/Form/NextSiteForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,32 @@ public function form(array $form, FormStateInterface $form_state) {
];

$form['preview'] = [
'#title' => $this->t('Preview Mode'),
'#description' => $this->t('Preview mode allows editors to preview content on the site. You can read more on the <a href=":uri" target="_blank">Next.js documentation</a>.', [
':uri' => 'https://nextjs.org/docs/advanced-features/preview-mode',
'#title' => $this->t('Draft Mode'),
'#description' => $this->t('Draft mode (or the deprecated Preview mode) allows editors to preview content on the site. You can read more on the <a href=":uri" target="_blank">Next.js documentation</a>.', [
':uri' => 'https://nextjs.org/docs/app/building-your-application/configuring/draft-mode',
]),
'#type' => 'details',
'#group' => 'settings',
];

$form['preview']['preview_url'] = [
'#type' => 'url',
'#title' => $this->t('Preview URL'),
'#description' => $this->t('Enter the preview URL. Example: <em>https://example.com/api/preview</em>.'),
'#title' => $this->t('Draft URL (or Preview URL)'),
'#description' => $this->t('Enter the draft URL or preview URL. Example: <em>https://example.com/api/draft</em> or <em>https://example.com/api/preview</em>.'),
'#default_value' => $entity->getPreviewUrl(),
];

$form['preview']['preview_secret'] = [
'#type' => 'textfield',
'#title' => $this->t('Preview secret'),
'#description' => $this->t('Enter a secret for the site preview. This is the same value used for <em>DRUPAL_PREVIEW_SECRET</em>.'),
'#title' => $this->t('Secret key'),
'#description' => $this->t('Enter a secret for the site draft/preview. This must be unique for each Next.js site'),
'#default_value' => $entity->getPreviewSecret(),
];

$form['revalidation'] = [
'#title' => $this->t('On-demand Revalidation'),
'#description' => $this->t('On-demand revalidation updates your pages when content is updated on your Drupal site. You can read more on the <a href=":uri" target="_blank">Next.js documentation</a>.', [
':uri' => 'https://nextjs.org/docs/advanced-features/preview-mode',
':uri' => 'https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#revalidating-data',
]),
'#type' => 'details',
'#group' => 'settings',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public function defaultConfiguration() {
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['secret_expiration'] = [
'#title' => $this->t('Preview secret expiration time'),
'#description' => $this->t('The value, in seconds, to be used as expiration time for the preview secret. <strong>It is recommended to use short-lived secrets for increased security.</strong>'),
'#title' => $this->t('Secret expiration time'),
'#description' => $this->t('The value, in seconds, to be used as expiration time for the validation secret. <strong>It is recommended to use short-lived secrets for increased security.</strong>'),
'#type' => 'number',
'#required' => TRUE,
'#default_value' => $this->configuration['secret_expiration'],
Expand Down

0 comments on commit a307486

Please sign in to comment.