Skip to content

Commit 093401e

Browse files
committed
minor #14185 Leave impersonation functions (dFayet)
This PR was merged into the master branch. Discussion ---------- Leave impersonation functions Will solve #14183 Documents new Twig functions `impersonation_exit_path` and `impersonation_exit_url` added in symfony/symfony#32841 Commits ------- b7bd572 Leave impersonation functions
2 parents 370fd2d + b7bd572 commit 093401e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

reference/twig_reference.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,33 @@ expression
267267
Creates an :class:`Symfony\\Component\\ExpressionLanguage\\Expression` related
268268
to the :doc:`ExpressionLanguage component </components/expression_language>`.
269269

270+
impersonation_exit_path
271+
~~~~~~~~~~~~~~~~~~~~~~~
272+
273+
.. code-block:: twig
274+
275+
{{ impersonation_exit_path(exitTo = null) }}
276+
277+
``exitTo`` *(optional)*
278+
**type**: ``string``
279+
280+
Generates a relative URL to exit impersonation. If `exitTo` is specified it will use its value to build the URl,
281+
elsewhere it will use the current URI.
282+
If we are not impersonating a user, it will return an empty string.
283+
284+
impersonation_exit_url
285+
~~~~~~~~~~~~~~~~~~~~~~
286+
287+
.. code-block:: twig
288+
289+
{{ impersonation_exit_url(exitTo = null) }}
290+
291+
``exitTo`` *(optional)*
292+
**type**: ``string``
293+
294+
Equal to the `impersonation_exit_path`_ function, but it'll generate an absolute URL
295+
instead of a relative one.
296+
270297
Form Related Functions
271298
~~~~~~~~~~~~~~~~~~~~~~
272299

security/impersonating_user.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ instance, to show a link to exit impersonation in a template:
9494
.. code-block:: html+twig
9595

9696
{% if is_granted('IS_IMPERSONATOR') %}
97-
<a href="{{ path('homepage', {'_switch_user': '_exit'}) }}">Exit impersonation</a>
97+
<a href="{{ impersonation_exit_path(path('homepage') ) }}">Exit impersonation</a>
9898
{% endif %}
9999

100100
.. versionadded:: 5.1

0 commit comments

Comments
 (0)