You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling the getCpEditUrl() method on a User element, it would be helpful to be able to bypass the $this->getIsCurrent() check that forces the URL to point to myaccount if you're the current user. I want something like this:
public function getCpEditUrl(bool $forceUrl = false)
{
if ($this->getIsCurrent() && ! $forceUrl) {
return UrlHelper::cpUrl('myaccount');
}
if (Craft::$app->getEdition() === Craft::Pro) {
return UrlHelper::cpUrl('users/' . $this->id);
}
return null;
}
instead of
public function getCpEditUrl()
{
if ($this->getIsCurrent()) {
return UrlHelper::cpUrl('myaccount');
}
if (Craft::$app->getEdition() === Craft::Pro) {
return UrlHelper::cpUrl('users/' . $this->id);
}
return null;
}
A good use case would be a form that gets submitted on the front end somewhere and a notification email that gets sent to some site admin email address. Let's say the email template provides some data on the registered User who submitted the form. I like to conveniently provide a link to the user's CP account easily for the admins who receive the email, but if you're logged in when you submit the form, the email template code detects this and makes the cpEditUrl point to myaccount, so if one of those admins clicks that link, it ends up taking them to their account and not mine.
Bypassing that check could then be as simple as {{ user.getCpEditUrl(true) }} to make all links go to the url with the user ID in it.
Additional info
Craft version: 3.4.25
The text was updated successfully, but these errors were encountered:
getCpUrl() is part of the element interface, so not something user elements can modify like that, but I’ve changed its behavior so /myaccount is only returned if the method is called within the control panel, for the next release.
Description
When calling the
getCpEditUrl()
method on aUser
element, it would be helpful to be able to bypass the$this->getIsCurrent()
check that forces the URL to point tomyaccount
if you're the current user. I want something like this:instead of
A good use case would be a form that gets submitted on the front end somewhere and a notification email that gets sent to some site admin email address. Let's say the email template provides some data on the registered
User
who submitted the form. I like to conveniently provide a link to the user's CP account easily for the admins who receive the email, but if you're logged in when you submit the form, the email template code detects this and makes thecpEditUrl
point tomyaccount
, so if one of those admins clicks that link, it ends up taking them to their account and not mine.Bypassing that check could then be as simple as
{{ user.getCpEditUrl(true) }}
to make all links go to the url with the user ID in it.Additional info
The text was updated successfully, but these errors were encountered: