Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

47 linhas
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. ->setRequired(true)
  17. ->setTemplatePath('@LcCaracole/admin/section/field/section.html.twig')
  18. ->setFormTypeOption('choices', $sectionArray)
  19. ]);
  20. }
  21. public function addSectionToFieldArrayIfOutOfSection(?SectionInterface $sectionCurrent, array $fieldArray)
  22. {
  23. $asObject = true;
  24. if(is_string($fieldArray[array_key_first($fieldArray)])) {
  25. $asObject = false;
  26. }
  27. $fieldSectionArray = [];
  28. if($sectionCurrent == null) {
  29. if($asObject) {
  30. $allFieldArray = $this->getAllFields();
  31. $fieldSectionArray = [$allFieldArray['section']];
  32. }
  33. else {
  34. $fieldSectionArray = ['section'];
  35. }
  36. }
  37. return array_merge($fieldSectionArray, $fieldArray);
  38. }
  39. }