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.

89 lines
2.8KB

  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\ImageManagerField;
  11. use Lc\SovBundle\Field\ToggleField;
  12. use Lc\SovBundle\Translation\TranslatorAdmin;
  13. class ProductCategoryFieldDefinition extends AbstractFieldDefinition
  14. {
  15. protected SectionStore $sectionStore;
  16. protected ProductCategoryStore $productCategoryStore;
  17. public function __construct(
  18. TranslatorAdmin $translatorAdmin,
  19. SectionStore $sectionStore,
  20. ProductCategoryStore $productCategoryStore
  21. ) {
  22. parent::__construct($translatorAdmin);
  23. $this->sectionStore = $sectionStore;
  24. $this->productCategoryStore = $productCategoryStore;
  25. }
  26. public function configureIndex(): array
  27. {
  28. $fieldArray = ($this->section == null) ? ['section'] : [];
  29. return array_merge($fieldArray, [
  30. 'id',
  31. 'title',
  32. 'position',
  33. 'createdAt',
  34. 'updatedAt',
  35. 'status',
  36. 'saleStatus',
  37. 'isEligibleTicketRestaurant'
  38. ]);
  39. }
  40. public function configurePanels(): array
  41. {
  42. return [
  43. 'main',
  44. 'seo',
  45. 'opengraph',
  46. 'conf'
  47. ];
  48. }
  49. public function configurePanelMain(): array
  50. {
  51. return [
  52. 'section',
  53. 'parent',
  54. 'title',
  55. 'description',
  56. 'image',
  57. 'status',
  58. 'saleStatus',
  59. 'isEligibleTicketRestaurant',
  60. ];
  61. }
  62. public function configureFields(): array
  63. {
  64. $productCategoryArray = $this->productCategoryStore
  65. ->setSection($this->section)
  66. ->getParents();
  67. return [
  68. 'title' => TextField::new('title')->setSortable(true),
  69. 'position' => NumberField::new('position')->setSortable(true),
  70. 'parent' => AssociationField::new('parent')
  71. ->setFormTypeOption('choices', $productCategoryArray),
  72. 'image' => ImageManagerField::new('image'),
  73. 'description' => CKEditorField::new('description'),
  74. 'saleStatus' => ToggleField::new('saleStatus')->setSortable(true),
  75. 'isEligibleTicketRestaurant' => ToggleField::new('isEligibleTicketRestaurant')->setSortable(true),
  76. ];
  77. }
  78. }