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.

80 lines
2.5KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Definition\Field\Product;
  3. use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
  4. use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
  5. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  6. use Lc\CaracoleBundle\Definition\Field\AbstractFieldDefinition;
  7. use Lc\CaracoleBundle\Repository\Product\ProductCategoryStore;
  8. use Lc\CaracoleBundle\Repository\Section\SectionStore;
  9. use Lc\SovBundle\Field\CKEditorField;
  10. use Lc\SovBundle\Field\ToggleField;
  11. use Lc\SovBundle\Translation\TranslatorAdmin;
  12. class ProductCategoryFieldDefinition extends AbstractFieldDefinition
  13. {
  14. protected SectionStore $sectionStore;
  15. protected ProductCategoryStore $productCategoryStore;
  16. public function __construct(
  17. TranslatorAdmin $translatorAdmin,
  18. SectionStore $sectionStore,
  19. ProductCategoryStore $productCategoryStore
  20. ) {
  21. parent::__construct($translatorAdmin);
  22. $this->sectionStore = $sectionStore;
  23. $this->productCategoryStore = $productCategoryStore;
  24. }
  25. public function configureIndex(): array
  26. {
  27. $fieldArray = ($this->section == null) ? ['section'] : [];
  28. return array_merge($fieldArray, [
  29. 'id',
  30. 'title',
  31. 'status'
  32. ]);
  33. }
  34. public function configurePanels(): array
  35. {
  36. return [
  37. 'main',
  38. 'seo',
  39. 'conf'
  40. ];
  41. }
  42. public function configurePanelMain()
  43. {
  44. return [
  45. 'section',
  46. 'title',
  47. 'parent',
  48. 'description',
  49. 'isEligibleTicketRestaurant',
  50. 'saleStatus',
  51. 'status',
  52. ];
  53. }
  54. public function configureFields(): array
  55. {
  56. $productCategoryArray = $this->productCategoryStore
  57. ->setSection($this->section)
  58. ->getParents();
  59. return [
  60. 'title' => TextField::new('title')->setSortable(true),
  61. 'position' => NumberField::new('position')->setSortable(true),
  62. 'parent' => AssociationField::new('parent')
  63. ->setFormTypeOption('choices', $productCategoryArray),
  64. 'description' => CKEditorField::new('description'),
  65. 'saleStatus' => ToggleField::new('saleStatus')->setSortable(true),
  66. 'isEligibleTicketRestaurant' => ToggleField::new('isEligibleTicketRestaurant')->setSortable(true),
  67. ];
  68. }
  69. }