Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

51 lines
1.6KB

  1. <?php
  2. namespace Lc\SovBundle\Controller\User;
  3. use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
  4. use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
  5. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  6. use Lc\SovBundle\Container\User\UserContainer;
  7. use Lc\SovBundle\Controller\AbstractAdminController;
  8. use Lc\SovBundle\Definition\RolesDefinition;
  9. use Lc\SovBundle\Definition\RolesDefinitionInterface;
  10. use Lc\SovBundle\Doctrine\EntityManager;
  11. use Lc\SovBundle\Factory\User\UserFactory;
  12. use Lc\SovBundle\Translation\TranslatorAdmin;
  13. use Symfony\Component\HttpFoundation\RequestStack;
  14. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  15. abstract class UserAdminController extends AbstractAdminController
  16. {
  17. protected RolesDefinitionInterface $rolesDefinition;
  18. public function __construct(
  19. SessionInterface $session,
  20. RequestStack $request,
  21. EntityManager $em,
  22. TranslatorAdmin $translatorAdmin,
  23. RolesDefinitionInterface $rolesDefinition
  24. ) {
  25. $this->rolesDefinition = $rolesDefinition;
  26. }
  27. public function configureFields(string $pageName): iterable
  28. {
  29. return [
  30. EmailField::new('email'),
  31. TextField::new('lastname'),
  32. TextField::new('firstname'),
  33. ChoiceField::new('roles')
  34. ->allowMultipleChoices()
  35. ->autocomplete()
  36. ->setChoices($this->rolesDefinition->getRolesList())
  37. ];
  38. }
  39. public function createEntity(string $entityFqcn)
  40. {
  41. return $this->get(UserContainer::class)->getFactory()->create();
  42. }
  43. }