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

UserAdminController.php 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\User;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
  5. use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
  6. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  7. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  8. use Lc\CaracoleBundle\Resolver\SectionResolver;
  9. use Lc\SovBundle\Controller\AbstractAdminController;
  10. use Lc\SovBundle\Definition\RolesDefinition;
  11. use Lc\SovBundle\Definition\RolesDefinitionInterface;
  12. use Lc\SovBundle\Doctrine\EntityManager;
  13. use Lc\SovBundle\Model\User\UserInterface;
  14. use Lc\SovBundle\Translation\TranslatorAdmin;
  15. use Symfony\Component\Cache\Adapter\AdapterInterface;
  16. use Symfony\Component\HttpFoundation\RequestStack;
  17. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  18. use Lc\SovBundle\Controller\User\UserAdminController as SovUserAdminController;
  19. abstract class UserAdminController extends SovUserAdminController
  20. {
  21. public static function getSubscribedServices()
  22. {
  23. return array_merge(parent::getSubscribedServices(), [
  24. 'merchant_resolver' => MerchantResolver::class,
  25. 'section_resolver' => SectionResolver::class,
  26. ]);
  27. }
  28. public function __construct(
  29. SessionInterface $session,
  30. RequestStack $request,
  31. EntityManager $em,
  32. TranslatorAdmin $translatorAdmin,
  33. RolesDefinitionInterface $rolesDefinition,
  34. MerchantResolver $merchantResolver
  35. ) {
  36. parent::__construct($session, $request, $em, $translatorAdmin, $rolesDefinition);
  37. }
  38. public function updateEntity(EntityManagerInterface $entityManager, $entityInstance): void
  39. {
  40. $this->updateUserMerchantRoles($entityManager, $entityInstance);
  41. parent::updateEntity($entityManager,$entityInstance);
  42. }
  43. /* public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
  44. {
  45. $this->updateUserMerchantRoles($entityManager,$entityInstance);
  46. parent::updateEntity($entityManager,$entityInstance);
  47. }*/
  48. protected function updateUserMerchantRoles($entityManager, UserInterface $user){
  49. $userMerchant = $this->get('merchant_resolver')->getUserMerchant($user);
  50. if($userMerchant !== null){
  51. $userMerchant->setRoles($user->getRoles());
  52. //$entityManager->update($userMerchant);
  53. }
  54. }
  55. }