|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?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;
-
- public function configureFieldsBase(): array
- {
- $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)
- ]);
- }
-
- 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);
- }
- }
|