Skip to content

Commit a05fd39

Browse files
authored
Merge pull request #18483 from craftcms/bugfix/18473-edit-pages-redirect-back
redirect to referral URL on element save again + adjustment
2 parents 1cc099c + d1bb64a commit a05fd39

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- Element edit pages once again redirect to their referral URL on save. ([#18483](https://github.com/craftcms/cms/pull/18483))
56
- Added `craft\filters\IpRateLimitIdentity`. ([#18510](https://github.com/craftcms/cms/pull/18510))
67
- Removed thamtech/yii2-ratelimiter-advanced. ([#18510](https://github.com/craftcms/cms/pull/18510))
78
- Fixed a bug where global set GraphQL query caches weren’t getting invalidated when global sets were updated. ([#18479](https://github.com/craftcms/cms/issues/18479))
@@ -16,6 +17,7 @@
1617
- Fixed a JavaScript error that could occur on element edit pages.
1718
- Fixed a bug where cross-site validation errors weren’t preventing elements from getting saved. ([#18292](https://github.com/craftcms/cms/issues/18292))
1819
- Fixed a bug where failure messages when pasting elements weren’t getting displayed properly.
20+
- Fixed a bug where `craft\helpers\UrlHelper::cpReferralUrl()` was returning the referrer URL even if it had the same URI as the current page. ([#18483](https://github.com/craftcms/cms/pull/18483))
1921

2022
## 5.9.14 - 2026-02-25
2123

src/controllers/ElementsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public function actionEdit(?ElementInterface $element, ?int $elementId = null):
364364
[$docTitle, $title] = $this->_editElementTitles($element);
365365
$enabledForSite = $element->getEnabledForSite();
366366
$hasRoute = $element->getRoute() !== null;
367-
$redirectUrl = $this->request->getValidatedQueryParam('returnUrl') ?? ElementHelper::postEditUrl($element);
367+
$redirectUrl = $this->request->getValidatedQueryParam('returnUrl') ?? UrlHelper::cpReferralUrl() ?? ElementHelper::postEditUrl($element);
368368

369369
// Site statuses
370370
if ($canEditMultipleSites) {

src/helpers/UrlHelper.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,7 @@ public static function cpReferralUrl(): ?string
584584
{
585585
$referrer = Craft::$app->getRequest()->getReferrer();
586586

587-
// Make sure it didn't refer itself
588-
if ($referrer === Craft::$app->getRequest()->getFullUri()) {
587+
if ($referrer === null) {
589588
return null;
590589
}
591590

@@ -594,6 +593,15 @@ public static function cpReferralUrl(): ?string
594593
return null;
595594
}
596595

596+
// to ensure we're comparing uris strip base cp url and query string from the referrer first
597+
$referrerFullUri = ltrim(StringHelper::removeLeft($referrer, self::baseCpUrl()), '/');
598+
$referrerFullUri = substr($referrerFullUri, 0, strpos($referrerFullUri, '?') ?: null);
599+
600+
// Make sure it didn't refer itself
601+
if ($referrerFullUri === Craft::$app->getRequest()->getFullUri()) {
602+
return null;
603+
}
604+
597605
return $referrer;
598606
}
599607

0 commit comments

Comments
 (0)