You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FieldDefinitionTrait.php 1.4KB

пре 3 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. }