Skip to content

Commit 4d22a78

Browse files
committed
Merge branch '2.3' into 2.6
* 2.3: [#5015] Very small tweak [#5011] Adding one more fix I missed [#5011] Fixing minor build issue improved link fixed intendation and shortened the link Adding a break statement to improve the sample code Added an example about how to get the impersonating user object #4032 improved comments about em option tip for mapping definition
2 parents 04a12a5 + edd8618 commit 4d22a78

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

Diff for: book/doctrine.rst

+2
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ entities (the topic of :ref:`relations <book-doctrine-relations>` will be
778778
covered later), group, etc. For more information, see the official
779779
`Doctrine Query Language`_ documentation.
780780

781+
.. _book-doctrine-custom-repository-classes:
782+
781783
Custom Repository Classes
782784
~~~~~~~~~~~~~~~~~~~~~~~~~
783785

Diff for: cookbook/form/data_transformers.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ by calling ``addModelTransformer`` (or ``addViewTransformer`` - see
122122
{
123123
// ...
124124

125-
// this assumes that the entity manager was passed in as an option
125+
// the "em" is an option that you pass when creating your form. Check out
126+
// the 3rd argument to createForm in the next code block to see how this
127+
// is passed to the form (also see setDefaultOptions).
126128
$entityManager = $options['em'];
127129
$transformer = new IssueToNumberTransformer($entityManager);
128130

Diff for: cookbook/security/entity_provider.rst

+5
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,11 @@ The code below shows the implementation of the
583583
}
584584
}
585585

586+
.. tip::
587+
588+
Don't forget to add the repository class to the
589+
:ref:`mapping definition of your entity <book-doctrine-custom-repository-classes>`.
590+
586591
To finish the implementation, the configuration of the security layer must be
587592
changed to tell Symfony to use the new custom entity provider instead of the
588593
generic Doctrine entity provider. It's trivial to achieve by removing the

Diff for: cookbook/security/impersonating_user.rst

+17
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ to show a link to exit impersonation:
8686
</a>
8787
<?php endif ?>
8888

89+
In some cases you may need to get the object that represents the impersonating
90+
user rather than the impersonated user. Use the following snippet to iterate
91+
over the user's roles until you find one that a ``SwitchUserRole`` object::
92+
93+
use Symfony\Component\Security\Core\Role\SwitchUserRole;
94+
95+
$securityContext = $this->get('security.context');
96+
97+
if ($securityContext->isGranted('ROLE_PREVIOUS_ADMIN')) {
98+
foreach ($securityContext->getToken()->getRoles() as $role) {
99+
if ($role instanceof SwitchUserRole) {
100+
$impersonatingUser = $role->getSource()->getUser();
101+
break;
102+
}
103+
}
104+
}
105+
89106
Of course, this feature needs to be made available to a small group of users.
90107
By default, access is restricted to users having the ``ROLE_ALLOWED_TO_SWITCH``
91108
role. The name of this role can be modified via the ``role`` setting. For

0 commit comments

Comments
 (0)