Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

NewsFieldDefinition.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. }