|
- <?php
-
- namespace Lc\CaracoleBundle\Definition\Field;
-
- use Lc\CaracoleBundle\Context\MerchantContextTrait;
- use Lc\CaracoleBundle\Context\SectionContextTrait;
- use Lc\CaracoleBundle\Field\AssociationField;
- use Lc\CaracoleBundle\Model\Section\SectionInterface;
-
- trait FieldDefinitionTrait
- {
- use MerchantContextTrait;
- use SectionContextTrait;
-
- protected ?array $sectionArray = null;
-
- public function configureFieldsBase(): array
- {
- 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', $this->sectionArray)
- ]);
- }
-
- public function addSectionToFieldArrayIfOutOfSection(?SectionInterface $sectionCurrent, array $fieldArray)
- {
- $asObject = true;
- if(is_string($fieldArray[array_key_first($fieldArray)])) {
- $asObject = false;
- }
-
- $fieldSectionArray = [];
- if($sectionCurrent == null) {
- if($asObject) {
- $allFieldArray = $this->getAllFields();
- $fieldSectionArray = [$allFieldArray['section']];
- }
- else {
- $fieldSectionArray = ['section'];
- }
- }
-
- return array_merge($fieldSectionArray, $fieldArray);
- }
- }
|