Skip to content

Commit 18cb912

Browse files
committed
minor #20505 [Security] Add docs for is_granted_for_user() function (Nate Wiebe)
This PR was merged into the 7.3 branch. Discussion ---------- [Security] Add docs for `is_granted_for_user()` function Fixes #20489 Adds docs for new twig function: * symfony/symfony#59129 Commits ------- e1c23c7 Add docs for is_granted_for_user() function
2 parents a316ae8 + e1c23c7 commit 18cb912

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

reference/twig_reference.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,27 @@ Returns ``true`` if the current user has the given role.
174174
Optionally, an object can be passed to be used by the voter. More information
175175
can be found in :ref:`security-template`.
176176

177+
is_granted_for_user
178+
~~~~~~~~~~~~~~~~~~~
179+
180+
.. code-block:: twig
181+
182+
{{ is_granted_for_user(user, attribute, subject = null, field = null) }}
183+
184+
``user``
185+
**type**: ``object``
186+
``attribute``
187+
**type**: ``string``
188+
``subject`` *(optional)*
189+
**type**: ``object``
190+
``field`` *(optional)*
191+
**type**: ``string``
192+
193+
Returns ``true`` if the user is authorized for the specified attribute.
194+
195+
Optionally, an object can be passed to be used by the voter. More information
196+
can be found in :ref:`security-template`.
197+
177198
logout_path
178199
~~~~~~~~~~~
179200

security.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,17 @@ the built-in ``is_granted()`` helper function in any Twig template:
25492549

25502550
.. _security-isgranted:
25512551

2552+
Similarly, if you want to check if a specific user has a certain role, you can use
2553+
the built-in ``is_granted_for_user()`` helper function:
2554+
2555+
.. code-block:: html+twig
2556+
2557+
{% if is_granted_for_user(user, 'ROLE_ADMIN') %}
2558+
<a href="...">Delete</a>
2559+
{% endif %}
2560+
2561+
.. _security-isgrantedforuser:
2562+
25522563
Securing other Services
25532564
.......................
25542565

0 commit comments

Comments
 (0)