|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
-
- namespace Lc\CaracoleBundle\Definition\Field\Product;
-
- use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
- use Lc\CaracoleBundle\Definition\Field\AbstractFieldDefinition;
- use Lc\CaracoleBundle\Repository\Product\ProductCategoryStore;
- use Lc\CaracoleBundle\Repository\Section\SectionStore;
- use Lc\SovBundle\Field\CKEditorField;
- use Lc\SovBundle\Field\ImageManagerField;
- use Lc\SovBundle\Field\ToggleField;
- use Lc\SovBundle\Translation\TranslatorAdmin;
-
- class ProductCategoryFieldDefinition extends AbstractFieldDefinition
- {
- protected SectionStore $sectionStore;
- protected ProductCategoryStore $productCategoryStore;
-
- protected ?array $productCategoryArray = null;
-
- public function __construct(
- TranslatorAdmin $translatorAdmin,
- SectionStore $sectionStore,
- ProductCategoryStore $productCategoryStore
- ) {
- parent::__construct($translatorAdmin);
- $this->sectionStore = $sectionStore;
- $this->productCategoryStore = $productCategoryStore;
- }
-
- public function configureIndex(): array
- {
- $fieldArray = ($this->section == null) ? ['section'] : [];
-
- return array_merge($fieldArray, [
- 'id',
- 'title',
- 'position',
- 'createdAt',
- 'updatedAt',
- 'status',
- 'saleStatus',
- 'isEligibleTicketRestaurant'
- ]);
- }
-
- public function configurePanels(): array
- {
- return [
- 'main',
- 'seo',
- 'opengraph',
- 'conf'
- ];
- }
-
- public function configurePanelMain(): array
- {
- return [
- 'section',
- 'parent',
- 'title',
- 'description',
- 'image',
- 'status',
- 'saleStatus',
- 'isEligibleTicketRestaurant',
- ];
- }
-
- public function configureFields(): array
- {
- if(is_null($this->productCategoryArray)) {
- $this->productCategoryArray = $this->productCategoryStore
- ->setSection($this->section)
- ->getParents();
- }
-
- return [
- 'title' => TextField::new('title')->setSortable(true),
- 'position' => NumberField::new('position')->setSortable(true),
- 'parent' => AssociationField::new('parent')
- ->setFormTypeOption('choices', $this->productCategoryArray)
- ->setFormTypeOption(
- 'choice_label',
- function ($productCategory) {
- return $productCategory->getTitle() . ' (' . $productCategory->getSection() . ')';
- }
- ),
- 'image' => ImageManagerField::new('image'),
- 'description' => CKEditorField::new('description'),
- 'saleStatus' => ToggleField::new('saleStatus')->setSortable(true),
- 'isEligibleTicketRestaurant' => ToggleField::new('isEligibleTicketRestaurant')->setSortable(true),
- ];
- }
- }
|