diff --git a/src/Symfony/Bridge/Twig/CHANGELOG.md b/src/Symfony/Bridge/Twig/CHANGELOG.md index 4e8ed13101b8a..9bb7aa0c7f1f6 100644 --- a/src/Symfony/Bridge/Twig/CHANGELOG.md +++ b/src/Symfony/Bridge/Twig/CHANGELOG.md @@ -7,6 +7,7 @@ CHANGELOG * Allow an array to be passed as the first argument to the `importmap()` Twig function * Add `TemplatedEmail::locale()` to set the locale for the email rendering * Add `AppVariable::getEnabledLocales()` to retrieve the enabled locales + * Add `impersonation_path()` and `impersonation_url()` Twig functions 6.3 --- diff --git a/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php b/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php index be222b056729c..3c3881ad00d04 100644 --- a/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php @@ -69,7 +69,16 @@ public function getImpersonateExitPath(string $exitTo = null): string return $this->impersonateUrlGenerator->generateExitPath($exitTo); } - public function getImpersonatePath(string $identifier = null): string + public function getImpersonateUrl(string $identifier): string + { + if (null === $this->impersonateUrlGenerator) { + return ''; + } + + return $this->impersonateUrlGenerator->generateImpersonationUrl($identifier); + } + + public function getImpersonatePath(string $identifier): string { if (null === $this->impersonateUrlGenerator) { return ''; @@ -84,6 +93,7 @@ public function getFunctions(): array new TwigFunction('is_granted', $this->isGranted(...)), new TwigFunction('impersonation_exit_url', $this->getImpersonateExitUrl(...)), new TwigFunction('impersonation_exit_path', $this->getImpersonateExitPath(...)), + new TwigFunction('impersonation_url', $this->getImpersonateUrl(...)), new TwigFunction('impersonation_path', $this->getImpersonatePath(...)), ]; } diff --git a/src/Symfony/Component/Security/Http/Impersonate/ImpersonateUrlGenerator.php b/src/Symfony/Component/Security/Http/Impersonate/ImpersonateUrlGenerator.php index a99dd89f0225d..f28d063ecbf88 100644 --- a/src/Symfony/Component/Security/Http/Impersonate/ImpersonateUrlGenerator.php +++ b/src/Symfony/Component/Security/Http/Impersonate/ImpersonateUrlGenerator.php @@ -36,11 +36,20 @@ public function __construct(RequestStack $requestStack, FirewallMap $firewallMap $this->firewallMap = $firewallMap; } - public function generateImpersonationPath(string $identifier = null): string + public function generateImpersonationPath(string $identifier): string { return $this->buildPath(null, $identifier); } + public function generateImpersonationUrl(string $identifier): string + { + if (null === $request = $this->requestStack->getCurrentRequest()) { + return ''; + } + + return $request->getUriForPath($this->buildPath(null, $identifier)); + } + public function generateExitPath(string $targetUri = null): string { return $this->buildPath($targetUri); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy