您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

UserAdminController.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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\Translation\TranslatorAdmin;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  13. abstract class UserAdminController extends AbstractAdminController
  14. {
  15. protected $rolesDefinition;
  16. public function __construct(
  17. SessionInterface $session,
  18. RequestStack $request,
  19. EntityManager $em,
  20. TranslatorAdmin $translatorAdmin,
  21. RolesDefinitionInterface $rolesDefinition
  22. ) {
  23. parent::__construct($session, $request, $em, $translatorAdmin);
  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. }