|
- <?php
-
- namespace Lc\CaracoleBundle\Definition\Field\User;
-
- use Lc\CaracoleBundle\Context\MerchantContextTrait;
- use Lc\CaracoleBundle\Field\AssociationField;
- use Lc\CaracoleBundle\Repository\Newsletter\NewsletterStore;
- use Lc\CaracoleBundle\Repository\User\GroupUserStore;
- use Lc\SovBundle\Definition\Field\User\UserFieldDefinition as SovUserFieldDefinition;
- use Lc\SovBundle\Definition\RolesDefinition;
- use Lc\SovBundle\Field\BooleanField;
- use Lc\SovBundle\Translation\TranslatorAdmin;
-
- use function Clue\StreamFilter\fun;
-
- class UserFieldDefinition extends SovUserFieldDefinition
- {
- use MerchantContextTrait;
-
- protected GroupUserStore $groupUserStore;
- protected NewsletterStore $newsletterStore;
-
- public function __construct(TranslatorAdmin $translatorAdmin, RolesDefinition $rolesDefinition, GroupUserStore $groupUserStore, NewsletterStore $newsletterStore)
- {
- parent::__construct($translatorAdmin, $rolesDefinition);
-
- $this->groupUserStore = $groupUserStore;
- $this->newsletterStore = $newsletterStore;
- }
-
- public function configureForm(): array
- {
- return [
- 'gender',
- 'lastname',
- 'firstname',
- 'email',
- 'phone',
- 'birthdate',
- 'groupUsers',
- 'isSaleAlwaysOpen',
- 'newsletters'
- ];
- }
-
- public function configureFields(): array
- {
- $groupUsers = $this->groupUserStore->setMerchant($this->merchant)->getAll();
- $newsletters = $this->newsletterStore->getAll();
-
- return array_merge(parent::configureFields(),[
- 'isSaleAlwaysOpen' => BooleanField::new('isSaleAlwaysOpen'),
- 'newsletters' => AssociationField::new('newsletters')
- ->setFormTypeOption('choices', $newsletters)
- ->setFormTypeOption('choice_label', function ($choice) {
- return $choice->getTitle(). '['.$choice->getSection()->getMerchant().']';
- })
- ->setSortable(true),
- 'groupUsers' => AssociationField::new('groupUsers')
- ->setFormTypeOption('choices', $groupUsers)
- ->setFormTypeOption('choice_label', function ($choice) {
- return $choice->getTitle(). '['.$choice->getMerchant().']';
- })
- ->setSortable(true)
-
- ]);
- }
-
- }
|