src/Controller/AdminController.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Client;
  4. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  5. use EasyCorp\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdminController;
  6. use App\Entity\User;
  7. class AdminController extends BaseAdminController
  8. {
  9.     private $encoder;
  10.     public function __construct(UserPasswordEncoderInterface $encoder)
  11.     {
  12.         $this->encoder $encoder;
  13.     }
  14.     protected function persistUserEntity($entity)
  15.     {
  16.         // Manually encode the new users' password
  17.         $entity->setPassword($this->encoder->encodePassword($entity$entity->getPlainPassword()));
  18.         return parent::persistEntity($entity);
  19.     }
  20.     protected function updateUserEntity($entity)
  21.     {
  22.         // Manually encode the edited users' password if needed
  23.         if ($entity->getPlainPassword()) {
  24.             $entity->setPassword($this->encoder->encodePassword($entity$entity->getPlainPassword()));
  25.         }
  26.         return parent::updateEntity($entity);
  27.     }
  28.     // Ces 2 méthodes permettent une bonne sérialisation de redirectUris si on supprime des valeurs
  29.     protected function persistClientEntity($entity)
  30.     {
  31.         /** @var Client $entity */
  32.         $entity->setRedirectUris(array_values($entity->getRedirectUris()));
  33.         return parent::persistEntity($entity);
  34.     }
  35.     protected function updateClientEntity($entity)
  36.     {
  37.         /** @var Client $entity */
  38.         $entity->setRedirectUris(array_values($entity->getRedirectUris()));
  39.         return parent::updateEntity($entity);
  40.     }
  41. }