<?php
namespace App\Controller;
use App\Entity\Client;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdminController;
use App\Entity\User;
class AdminController extends BaseAdminController
{
private $encoder;
public function __construct(UserPasswordEncoderInterface $encoder)
{
$this->encoder = $encoder;
}
protected function persistUserEntity($entity)
{
// Manually encode the new users' password
$entity->setPassword($this->encoder->encodePassword($entity, $entity->getPlainPassword()));
return parent::persistEntity($entity);
}
protected function updateUserEntity($entity)
{
// Manually encode the edited users' password if needed
if ($entity->getPlainPassword()) {
$entity->setPassword($this->encoder->encodePassword($entity, $entity->getPlainPassword()));
}
return parent::updateEntity($entity);
}
// Ces 2 méthodes permettent une bonne sérialisation de redirectUris si on supprime des valeurs
protected function persistClientEntity($entity)
{
/** @var Client $entity */
$entity->setRedirectUris(array_values($entity->getRedirectUris()));
return parent::persistEntity($entity);
}
protected function updateClientEntity($entity)
{
/** @var Client $entity */
$entity->setRedirectUris(array_values($entity->getRedirectUris()));
return parent::updateEntity($entity);
}
}