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.

87 lines
2.7KB

  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. 'conf'
  46. ];
  47. }
  48. public function configurePanelMain(): array
  49. {
  50. return [
  51. 'section',
  52. 'parent',
  53. 'title',
  54. 'description',
  55. 'image',
  56. 'saleStatus',
  57. 'isEligibleTicketRestaurant',
  58. ];
  59. }
  60. public function configureFields(): array
  61. {
  62. $productCategoryArray = $this->productCategoryStore
  63. ->setSection($this->section)
  64. ->getParents();
  65. return [
  66. 'title' => TextField::new('title')->setSortable(true),
  67. 'position' => NumberField::new('position')->setSortable(true),
  68. 'parent' => AssociationField::new('parent')
  69. ->setFormTypeOption('choices', $productCategoryArray),
  70. 'image' => ImageManagerField::new('image'),
  71. 'description' => CKEditorField::new('description'),
  72. 'saleStatus' => ToggleField::new('saleStatus')->setSortable(true),
  73. 'isEligibleTicketRestaurant' => ToggleField::new('isEligibleTicketRestaurant')->setSortable(true),
  74. ];
  75. }
  76. }