src/Controller/Admin/UserAdminController.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Entity\User;
  4. use Sonata\AdminBundle\Controller\CRUDController;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. class UserAdminController extends CRUDController
  8. {
  9.     public function impersonateAction($id)
  10.     {
  11.         /** @var User $object */
  12.         $object $this->admin->getSubject();
  13.         if (!$object) {
  14.             throw new NotFoundHttpException(sprintf('unable to find the object with id: %s'$id));
  15.         }
  16.         return new RedirectResponse($this->generateUrl('_home', ['_switch_user' => $object->getName()]));
  17.     }
  18. }