選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

46 行
1.4KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Definition\Field;
  3. use Lc\CaracoleBundle\Context\MerchantContextTrait;
  4. use Lc\CaracoleBundle\Context\SectionContextTrait;
  5. use Lc\CaracoleBundle\Field\AssociationField;
  6. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  7. trait FieldDefinitionTrait
  8. {
  9. use MerchantContextTrait;
  10. use SectionContextTrait;
  11. public function configureFieldsBase(): array
  12. {
  13. $sectionArray = $this->sectionStore->setMerchant($this->merchant)->get();
  14. return array_merge(parent::configureFieldsBase(), [
  15. 'section' => AssociationField::new('section')
  16. ->setTemplatePath('@LcCaracole/admin/section/field/section.html.twig')
  17. ->setFormTypeOption('choices', $sectionArray)
  18. ]);
  19. }
  20. public function addSectionToFieldArrayIfOutOfSection(?SectionInterface $sectionCurrent, array $fieldArray)
  21. {
  22. $asObject = true;
  23. if(is_string($fieldArray[array_key_first($fieldArray)])) {
  24. $asObject = false;
  25. }
  26. $fieldSectionArray = [];
  27. if($sectionCurrent == null) {
  28. if($asObject) {
  29. $allFieldArray = $this->getAllFields();
  30. $fieldSectionArray = [$allFieldArray['section']];
  31. }
  32. else {
  33. $fieldSectionArray = ['section'];
  34. }
  35. }
  36. return array_merge($fieldSectionArray, $fieldArray);
  37. }
  38. }