@@ -12,14 +12,19 @@ trait FieldDefinitionTrait | |||
use MerchantContextTrait; | |||
use SectionContextTrait; | |||
protected ?array $sectionArray = null; | |||
public function configureFieldsBase(): array | |||
{ | |||
$sectionArray = $this->sectionStore->setMerchant($this->merchant)->get(); | |||
if(is_null($this->sectionArray)){ | |||
$this->sectionArray = $this->sectionStore->setMerchant($this->merchant)->get(); | |||
} | |||
return array_merge(parent::configureFieldsBase(), [ | |||
'section' => AssociationField::new('section') | |||
->setTemplatePath('@LcCaracole/admin/section/field/section.html.twig') | |||
->setFormTypeOption('choices', $sectionArray) | |||
->setFormTypeOption('choices', $this->sectionArray) | |||
]); | |||
} | |||
@@ -18,6 +18,8 @@ class ProductCategoryFieldDefinition extends AbstractFieldDefinition | |||
protected SectionStore $sectionStore; | |||
protected ProductCategoryStore $productCategoryStore; | |||
protected ?array $productCategoryArray = null; | |||
public function __construct( | |||
TranslatorAdmin $translatorAdmin, | |||
SectionStore $sectionStore, | |||
@@ -70,15 +72,17 @@ class ProductCategoryFieldDefinition extends AbstractFieldDefinition | |||
public function configureFields(): array | |||
{ | |||
$productCategoryArray = $this->productCategoryStore | |||
if(is_null($this->productCategoryArray)) { | |||
$this->productCategoryArray = $this->productCategoryStore | |||
->setSection($this->section) | |||
->getParents(); | |||
} | |||
return [ | |||
'title' => TextField::new('title')->setSortable(true), | |||
'position' => NumberField::new('position')->setSortable(true), | |||
'parent' => AssociationField::new('parent') | |||
->setFormTypeOption('choices', $productCategoryArray) | |||
->setFormTypeOption('choices', $this->productCategoryArray) | |||
->setFormTypeOption( | |||
'choice_label', | |||
function ($productCategory) { |
@@ -12,6 +12,8 @@ class NewsFieldDefinition extends SovNewsFieldDefinition | |||
{ | |||
use FieldDefinitionTrait; | |||
protected ?array $newsletterArray = null; | |||
protected SectionStore $sectionStore; | |||
protected NewsletterStore $newsletterStore; | |||
@@ -36,12 +38,14 @@ class NewsFieldDefinition extends SovNewsFieldDefinition | |||
{ | |||
$fieldArray = parent::configureFields(); | |||
$newsletterArray = $this->newsletterStore | |||
if(is_null($this->newsletterArray)){ | |||
$this->newsletterArray = $this->newsletterStore | |||
->setSection($this->section) | |||
->setMerchant($this->merchant) | |||
->get(); | |||
} | |||
$fieldArray['newsletter']->setFormTypeOption('choices', $newsletterArray); | |||
$fieldArray['newsletter']->setFormTypeOption('choices', $this->newsletterArray); | |||
return $fieldArray; | |||
} |
@@ -21,15 +21,19 @@ class UserFieldDefinition extends SovUserFieldDefinition | |||
{ | |||
use MerchantContextTrait; | |||
protected ?array $newsletterArray = null; | |||
protected ?array $groupUserArray = null; | |||
protected GroupUserStore $groupUserStore; | |||
protected NewsletterStore $newsletterStore; | |||
public function __construct( | |||
TranslatorAdmin $translatorAdmin, | |||
RolesDefinition $rolesDefinition, | |||
GroupUserStore $groupUserStore, | |||
GroupUserStore $groupUserStore, | |||
NewsletterStore $newsletterStore | |||
) { | |||
) | |||
{ | |||
parent::__construct($translatorAdmin, $rolesDefinition); | |||
$this->groupUserStore = $groupUserStore; | |||
@@ -70,19 +74,24 @@ class UserFieldDefinition extends SovUserFieldDefinition | |||
public function configureFields(): array | |||
{ | |||
$groupUsers = $this->groupUserStore->setMerchant($this->merchant)->getAll(); | |||
$newsletters = $this->newsletterStore->getAll(); | |||
if (is_null($this->newsletterArray)) { | |||
$this->newsletterArray = $this->newsletterStore->getAll(); | |||
} | |||
if (is_null($this->groupUserArray)) { | |||
$this->groupUserArray = $this->groupUserStore->setMerchant($this->merchant)->getAll(); | |||
} | |||
return array_merge(parent::configureFields(), [ | |||
'isSaleAlwaysOpen' => BooleanField::new('isSaleAlwaysOpen'), | |||
'newsletters' => AssociationField::new('newsletters') | |||
->setFormTypeOption('choices', $newsletters) | |||
->setFormTypeOption('choices', $this->newsletterArray) | |||
->setFormTypeOption('choice_label', function ($choice) { | |||
return $choice->getTitle() . '[' . $choice->getSection()->getMerchant() . ']'; | |||
}) | |||
->setSortable(true), | |||
'groupUsers' => AssociationField::new('groupUsers') | |||
->setFormTypeOption('choices', $groupUsers) | |||
->setFormTypeOption('choices', $this->groupUserArray) | |||
->setCustomOption('class', GroupUser::class) | |||
->setTemplatePath('@LcSov/adminlte/crud/field/association_many.html.twig') | |||
->setFormTypeOption('choice_label', function ($choice) { |