Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

UserAdminController.php 3.0KB

vor 3 Jahren
vor 3 Jahren
vor 3 Jahren
vor 3 Jahren
vor 3 Jahren
vor 3 Jahren
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }