Skip to content

Commit 72d1d57

Browse files
committed
Maintain preview URL params
Resolves #15447
1 parent a1df5de commit 72d1d57

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

CHANGELOG-WIP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- `{% cache %}` tags now cache any asset bundles registered within them.
2121
- Country field values are now set to `CommerceGuys\Addressing\Country\Country` objects. ([#15463](https://github.com/craftcms/cms/pull/15463))
2222
- Auto-populated section and category group Template settings are now suffixed with `.twig`.
23+
- `x-craft-preview`/`x-craft-live-preview` URL query string params are now added to generated URLs for Live Preview requests, so `craft\web\Request::getIsPreview()` continues to return `true` on subsequent pages loaded within the iframe. ([#15447](https://github.com/craftcms/cms/discussions/15447))
2324

2425
### Extensibility
2526
- Added `craft\config\GeneralConfig::addAlias()`. ([#15346](https://github.com/craftcms/cms/pull/15346))

src/helpers/UrlHelper.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,20 @@ private static function _createUrl(
629629
$params['site'] = Cp::requestedSite()->handle;
630630
}
631631
} else {
632-
// token/siteToken params
632+
// token/siteToken/preview params
633633
if ($addToken && !isset($params[$generalConfig->tokenParam]) && ($token = $request->getToken()) !== null) {
634634
$params[$generalConfig->tokenParam] = $token;
635635
}
636636
if (!isset($params[$generalConfig->siteToken]) && ($siteToken = $request->getSiteToken()) !== null) {
637637
$params[$generalConfig->siteToken] = $siteToken;
638638
}
639+
if (!isset($params['x-craft-preview']) && !isset($params['x-craft-live-preview'])) {
640+
if (($previewToken = $request->getQueryParam('x-craft-preview')) !== null) {
641+
$params['x-craft-preview'] = $previewToken;
642+
} elseif (($previewToken = $request->getQueryParam('x-craft-live-preview')) !== null) {
643+
$params['x-craft-live-preview'] = $previewToken;
644+
}
645+
}
639646
}
640647

641648
if ($showScriptName === null) {

0 commit comments

Comments
 (0)