No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

99 líneas
3.2KB

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