You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserAdminController.php 1.6KB

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