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.

53 satır
1.6KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Definition\Field\Site;
  3. use Lc\CaracoleBundle\Definition\Field\FieldDefinitionTrait;
  4. use Lc\CaracoleBundle\Repository\Newsletter\NewsletterStore;
  5. use Lc\CaracoleBundle\Repository\Section\SectionStore;
  6. use Lc\SovBundle\Definition\Field\Site\NewsFieldDefinition as SovNewsFieldDefinition;
  7. use Lc\SovBundle\Translation\TranslatorAdmin;
  8. class NewsFieldDefinition extends SovNewsFieldDefinition
  9. {
  10. use FieldDefinitionTrait;
  11. protected ?array $newsletterArray = null;
  12. protected SectionStore $sectionStore;
  13. protected NewsletterStore $newsletterStore;
  14. public function __construct(TranslatorAdmin $translatorAdmin, SectionStore $sectionStore, NewsletterStore $newsletterStore)
  15. {
  16. parent::__construct($translatorAdmin);
  17. $this->sectionStore = $sectionStore;
  18. $this->newsletterStore = $newsletterStore;
  19. }
  20. public function configureIndex(): array
  21. {
  22. return $this->addSectionToFieldArrayIfOutOfSection($this->section, parent::configureIndex());
  23. }
  24. public function configurePanelMain(): array
  25. {
  26. return array_merge(['section'], parent::configurePanelMain());
  27. }
  28. public function configureFields(): array
  29. {
  30. $fieldArray = parent::configureFields();
  31. if(is_null($this->newsletterArray)){
  32. $this->newsletterArray = $this->newsletterStore
  33. ->setSection($this->section)
  34. ->setMerchant($this->merchant)
  35. ->get();
  36. }
  37. $fieldArray['newsletter']->setFormTypeOption('choices', $this->newsletterArray);
  38. return $fieldArray;
  39. }
  40. }