<?php
namespace App\Controller\Admin;
use App\Entity\User;
use Sonata\AdminBundle\Controller\CRUDController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class UserAdminController extends CRUDController
{
public function impersonateAction($id)
{
/** @var User $object */
$object = $this->admin->getSubject();
if (!$object) {
throw new NotFoundHttpException(sprintf('unable to find the object with id: %s', $id));
}
return new RedirectResponse($this->generateUrl('_home', ['_switch_user' => $object->getName()]));
}
}