您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

51 行
1.5KB

  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. protected ?array $sectionArray = null;
  12. public function configureFieldsBase(): array
  13. {
  14. if(is_null($this->sectionArray)){
  15. $this->sectionArray = $this->sectionStore->setMerchant($this->merchant)->get();
  16. }
  17. return array_merge(parent::configureFieldsBase(), [
  18. 'section' => AssociationField::new('section')
  19. ->setTemplatePath('@LcCaracole/admin/section/field/section.html.twig')
  20. ->setFormTypeOption('choices', $this->sectionArray)
  21. ]);
  22. }
  23. public function addSectionToFieldArrayIfOutOfSection(?SectionInterface $sectionCurrent, array $fieldArray)
  24. {
  25. $asObject = true;
  26. if(is_string($fieldArray[array_key_first($fieldArray)])) {
  27. $asObject = false;
  28. }
  29. $fieldSectionArray = [];
  30. if($sectionCurrent == null) {
  31. if($asObject) {
  32. $allFieldArray = $this->getAllFields();
  33. $fieldSectionArray = [$allFieldArray['section']];
  34. }
  35. else {
  36. $fieldSectionArray = ['section'];
  37. }
  38. }
  39. return array_merge($fieldSectionArray, $fieldArray);
  40. }
  41. }