選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

80 行
3.0KB

  1. <?php
  2. namespace Lc\SovBundle\Controller\User;
  3. use EasyCorp\Bundle\EasyAdminBundle\Collection\EntityCollection;
  4. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  5. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  6. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  7. use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
  8. use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
  9. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  10. use Lc\SovBundle\Container\User\UserContainer;
  11. use Lc\SovBundle\Controller\AbstractAdminController;
  12. use Lc\SovBundle\Definition\ActionDefinition;
  13. use Lc\SovBundle\Definition\RolesDefinition;
  14. use Lc\SovBundle\Definition\RolesDefinitionInterface;
  15. use Lc\SovBundle\Doctrine\EntityManager;
  16. use Lc\SovBundle\Factory\User\UserFactory;
  17. use Lc\SovBundle\Translation\TranslatorAdmin;
  18. use Symfony\Component\HttpFoundation\RequestStack;
  19. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  20. abstract class UserAdminController extends AbstractAdminController
  21. {
  22. public function buildIndexActions(Actions $actions): void
  23. {
  24. parent::buildIndexActions($actions); // TODO: Change the autogenerated stub
  25. $actions->add(Crud::PAGE_INDEX, $this->getSwitchUserAction());
  26. }
  27. public function getSwitchUserAction(): Action
  28. {
  29. $switchAction = Action::new(
  30. ActionDefinition::SWITCH_USER,
  31. $this->get(TranslatorAdmin::class)->transAction(ActionDefinition::SWITCH_USER),
  32. 'fa fa-fw fa-user-secret'
  33. )
  34. ->linkToCrudAction(ActionDefinition::SWITCH_USER)
  35. ->setLabel($this->get(TranslatorAdmin::class)->transAction(ActionDefinition::SWITCH_USER))
  36. ->setCssClass('in-dropdown text-info action-confirm action_switch');
  37. return $switchAction;
  38. }
  39. public function overrideEntitiesActions(?EntityCollection $entities, string $pageName): void
  40. {
  41. parent::overrideEntitiesActions($entities, $pageName); // TODO: Change the autogenerated stub
  42. foreach ($entities as $entity) {
  43. foreach ($entity->getActions() as $action) {
  44. if ($action->getName() == ActionDefinition::SWITCH_USER) {
  45. $url = $this->generateUrl(
  46. $this->getParameter('lc_sov.homepage_route'),
  47. array('_switch_user' => $entity->getInstance()->getEmail())
  48. );
  49. $action->setLinkUrl($url);
  50. }
  51. }
  52. }
  53. }
  54. public function configureFields(string $pageName): iterable
  55. {
  56. return [
  57. EmailField::new('email'),
  58. TextField::new('lastname'),
  59. TextField::new('firstname'),
  60. ChoiceField::new('roles')
  61. ->allowMultipleChoices()
  62. ->autocomplete()
  63. ->setChoices($this->getUserContainer()->getRoleDefinition()->getRolesList())
  64. ];
  65. }
  66. public function createEntity(string $entityFqcn)
  67. {
  68. return $this->get(UserContainer::class)->getFactory()->create();
  69. }
  70. }