You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 satır
2.5KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Definition\Field\User;
  3. use Lc\CaracoleBundle\Context\MerchantContextTrait;
  4. use Lc\CaracoleBundle\Field\AssociationField;
  5. use Lc\CaracoleBundle\Repository\Newsletter\NewsletterStore;
  6. use Lc\CaracoleBundle\Repository\User\GroupUserStore;
  7. use Lc\SovBundle\Definition\Field\User\UserFieldDefinition as SovUserFieldDefinition;
  8. use Lc\SovBundle\Definition\RolesDefinition;
  9. use Lc\SovBundle\Field\BooleanField;
  10. use Lc\SovBundle\Translation\TranslatorAdmin;
  11. use function Clue\StreamFilter\fun;
  12. class UserFieldDefinition extends SovUserFieldDefinition
  13. {
  14. use MerchantContextTrait;
  15. protected GroupUserStore $groupUserStore;
  16. protected NewsletterStore $newsletterStore;
  17. public function __construct(TranslatorAdmin $translatorAdmin, RolesDefinition $rolesDefinition, GroupUserStore $groupUserStore, NewsletterStore $newsletterStore)
  18. {
  19. parent::__construct($translatorAdmin, $rolesDefinition);
  20. $this->groupUserStore = $groupUserStore;
  21. $this->newsletterStore = $newsletterStore;
  22. }
  23. public function configureForm(): array
  24. {
  25. return [
  26. 'gender',
  27. 'lastname',
  28. 'firstname',
  29. 'email',
  30. 'phone',
  31. 'birthdate',
  32. 'groupUsers',
  33. 'isSaleAlwaysOpen',
  34. 'newsletters'
  35. ];
  36. }
  37. public function configureFields(): array
  38. {
  39. $groupUsers = $this->groupUserStore->setMerchant($this->merchant)->getAll();
  40. $newsletters = $this->newsletterStore->getAll();
  41. return array_merge(parent::configureFields(),[
  42. 'isSaleAlwaysOpen' => BooleanField::new('isSaleAlwaysOpen'),
  43. 'newsletters' => AssociationField::new('newsletters')
  44. ->setFormTypeOption('choices', $newsletters)
  45. ->setFormTypeOption('choice_label', function ($choice) {
  46. return $choice->getTitle(). '['.$choice->getSection()->getMerchant().']';
  47. })
  48. ->setSortable(true),
  49. 'groupUsers' => AssociationField::new('groupUsers')
  50. ->setFormTypeOption('choices', $groupUsers)
  51. ->setFormTypeOption('choice_label', function ($choice) {
  52. return $choice->getTitle(). '['.$choice->getMerchant().']';
  53. })
  54. ->setSortable(true)
  55. ]);
  56. }
  57. }