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.

83 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. 'position',
  32. 'createdAt',
  33. 'status',
  34. 'saleStatus'
  35. ]);
  36. }
  37. public function configurePanels(): array
  38. {
  39. return [
  40. 'main',
  41. 'seo',
  42. 'conf'
  43. ];
  44. }
  45. public function configurePanelMain()
  46. {
  47. return [
  48. 'section',
  49. 'title',
  50. 'parent',
  51. 'description',
  52. 'isEligibleTicketRestaurant',
  53. 'saleStatus',
  54. 'status',
  55. ];
  56. }
  57. public function configureFields(): array
  58. {
  59. $productCategoryArray = $this->productCategoryStore
  60. ->setSection($this->section)
  61. ->getParents();
  62. return [
  63. 'title' => TextField::new('title')->setSortable(true),
  64. 'position' => NumberField::new('position')->setSortable(true),
  65. 'parent' => AssociationField::new('parent')
  66. ->setFormTypeOption('choices', $productCategoryArray),
  67. 'description' => CKEditorField::new('description'),
  68. 'saleStatus' => ToggleField::new('saleStatus')->setSortable(true),
  69. 'isEligibleTicketRestaurant' => ToggleField::new('isEligibleTicketRestaurant')->setSortable(true),
  70. ];
  71. }
  72. }