Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

UserAdminController.php 1.6KB

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\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. }