From a5fce5c99518006996ed68c2f08e492d4e124f56 Mon Sep 17 00:00:00 2001 From: Shubham Goel Date: Fri, 9 Jan 2026 14:39:47 +0530 Subject: [PATCH 1/2] DRCD-1999: Add per site preview functiuonality --- .../Next/PreviewUrlGenerator/SimpleOauth.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/next/src/Plugin/Next/PreviewUrlGenerator/SimpleOauth.php b/modules/next/src/Plugin/Next/PreviewUrlGenerator/SimpleOauth.php index 1ec530724..a3c8d146a 100644 --- a/modules/next/src/Plugin/Next/PreviewUrlGenerator/SimpleOauth.php +++ b/modules/next/src/Plugin/Next/PreviewUrlGenerator/SimpleOauth.php @@ -126,11 +126,14 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s */ public function generate(NextSiteInterface $next_site, EntityInterface $entity, string $resource_version = NULL): ?Url { $query = []; - $query['path'] = $path = $entity->toUrl()->toString(); + $query['slug'] = $slug = $entity->toUrl()->toString(); + if($resource_version) { + $query['path'] = $query['path'].'?resourceVersion='.$resource_version; + } - // Create a secret based on the timestamp, path, scope and resource version. + // Create a secret based on the timestamp, slug, scope and resource version. $query['timestamp'] = $timestamp = $this->time->getRequestTime(); - $query['secret'] = $this->previewSecretGenerator->generate($timestamp . $path . $resource_version); + $query['secret'] = $this->previewSecretGenerator->generate($timestamp . $slug . $resource_version); return Url::fromUri($next_site->getPreviewUrl(), [ 'query' => $query, @@ -143,10 +146,10 @@ public function generate(NextSiteInterface $next_site, EntityInterface $entity, public function validate(Request $request) { $body = Json::decode($request->getContent()); - // Validate the path. - // We do not check for existing path. We let the next.js site handle this. - if (empty($body['path'])) { - throw new InvalidPreviewUrlRequest("Field 'path' is missing"); + // Validate the slug. + // We do not check for existing slug. We let the next.js site handle this. + if (empty($body['slug'])) { + throw new InvalidPreviewUrlRequest("Field 'slug' is missing"); } // Validate the timestamp. @@ -164,12 +167,12 @@ public function validate(Request $request) { throw new InvalidPreviewUrlRequest("Field 'secret' is missing"); } - if ($body['secret'] !== $this->previewSecretGenerator->generate($body['timestamp'] . $body['path'] . $body['resourceVersion'])) { + if ($body['secret'] !== $this->previewSecretGenerator->generate($body['timestamp'] . $body['slug'] . $body['resourceVersion'])) { throw new InvalidPreviewUrlRequest("The provided secret is invalid."); } return [ - 'path' => $body['path'], + 'path' => $body['slug'], 'maxAge' => (int) $this->configuration['secret_expiration'], ]; } From 883ddf4e60ec528621dd3c036bd622772743e7e0 Mon Sep 17 00:00:00 2001 From: Shubham Goel Date: Fri, 9 Jan 2026 15:12:44 +0530 Subject: [PATCH 2/2] DRCD-1999: Add per site preview functiuonality --- .../Next/PreviewUrlGenerator/SimpleOauth.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/next/src/Plugin/Next/PreviewUrlGenerator/SimpleOauth.php b/modules/next/src/Plugin/Next/PreviewUrlGenerator/SimpleOauth.php index a3c8d146a..106803f16 100644 --- a/modules/next/src/Plugin/Next/PreviewUrlGenerator/SimpleOauth.php +++ b/modules/next/src/Plugin/Next/PreviewUrlGenerator/SimpleOauth.php @@ -126,14 +126,14 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s */ public function generate(NextSiteInterface $next_site, EntityInterface $entity, string $resource_version = NULL): ?Url { $query = []; - $query['slug'] = $slug = $entity->toUrl()->toString(); + $query['path'] = $path = $entity->toUrl()->toString(); if($resource_version) { $query['path'] = $query['path'].'?resourceVersion='.$resource_version; } - // Create a secret based on the timestamp, slug, scope and resource version. + // Create a secret based on the timestamp, path, scope and resource version. $query['timestamp'] = $timestamp = $this->time->getRequestTime(); - $query['secret'] = $this->previewSecretGenerator->generate($timestamp . $slug . $resource_version); + $query['secret'] = $this->previewSecretGenerator->generate($timestamp . $path . $resource_version); return Url::fromUri($next_site->getPreviewUrl(), [ 'query' => $query, @@ -146,10 +146,10 @@ public function generate(NextSiteInterface $next_site, EntityInterface $entity, public function validate(Request $request) { $body = Json::decode($request->getContent()); - // Validate the slug. - // We do not check for existing slug. We let the next.js site handle this. - if (empty($body['slug'])) { - throw new InvalidPreviewUrlRequest("Field 'slug' is missing"); + // Validate the path. + // We do not check for existing path. We let the next.js site handle this. + if (empty($body['path'])) { + throw new InvalidPreviewUrlRequest("Field 'path' is missing"); } // Validate the timestamp. @@ -167,12 +167,12 @@ public function validate(Request $request) { throw new InvalidPreviewUrlRequest("Field 'secret' is missing"); } - if ($body['secret'] !== $this->previewSecretGenerator->generate($body['timestamp'] . $body['slug'] . $body['resourceVersion'])) { + if ($body['secret'] !== $this->previewSecretGenerator->generate($body['timestamp'] . $body['path'] . $body['resourceVersion'])) { throw new InvalidPreviewUrlRequest("The provided secret is invalid."); } return [ - 'path' => $body['slug'], + 'path' => $body['path'], 'maxAge' => (int) $this->configuration['secret_expiration'], ]; }