Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/craftcms-vue/admintable/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
isEmpty: false,
isLoading: true,
searchClearTitle: Craft.escapeHtml(Craft.t('app', 'Clear')),
searchTerm: '',
searchTerm: new URL(window.location.href).searchParams.get('q'),
selectAll: null,
sortable: null,
tableBodySelector: '.vuetable-body',
Expand Down Expand Up @@ -717,6 +717,10 @@
}
this.reload();
}
const url = new URL(window.location.href);
url.searchParams.set('q', this.searchTerm);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brandonkelly I don't think using q here will cause any issues, but if you think it's likely to run into another query param, we can use something else.

window.history.replaceState({}, '', url);
}, 500),
resetSearch: function () {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public function actionEdit(?ElementInterface $element, ?int $elementId = null):
$type = $element::lowerDisplayName();
$enabledForSite = $element->getEnabledForSite();
$hasRoute = $element->getRoute() !== null;
$redirectUrl = ElementHelper::postEditUrl($element);
$redirectUrl = UrlHelper::cpReferralUrl() ?? $element->getPostEditUrl() ?? Craft::$app->getConfig()->getGeneral()->getPostCpLoginRedirect();

// Site statuses
if ($canEditMultipleSites) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/FieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function actionEditField(?int $fieldId = null, ?FieldInterface $field = n
->addCrumb(Craft::t('app', 'Settings'), 'settings')
->addCrumb(Craft::t('app', 'Fields'), 'settings/fields')
->action('fields/save-field')
->redirectUrl('settings/fields')
->redirectUrl(UrlHelper::cpReferralUrl() ?? 'settings/fields')
->addAltAction(Craft::t('app', 'Save and continue editing'), [
'redirect' => 'settings/fields/edit/{id}',
'shortcut' => true,
Expand Down
23 changes: 23 additions & 0 deletions src/helpers/UrlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,29 @@ public static function cpHost(): string
return static::hostInfo(static::baseCpUrl());
}

/**
* Returns a CP referral URL.
*
* @return string|null
* @since 5.6.0
*/
public static function cpReferralUrl(): ?string
{
$referrer = Craft::$app->getRequest()->getReferrer();

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

// Make sure the CP referred it
if (!str_contains($referrer, self::baseCpUrl())) {
return null;
}

return $referrer;
}

/**
* Parses a URL for the host info.
*
Expand Down