src/Controller/Admin/ProductCrudController.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Entity\Product;
  4. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  5. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  6. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  7. use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
  8. use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
  9. use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
  10. use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
  11. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  12. class ProductCrudController extends AbstractCrudController
  13. {
  14.     public static function getEntityFqcn(): string
  15.     {
  16.         return Product::class;
  17.     }
  18.     public function configureActions(Actions $actions): Actions
  19.     {
  20.         return $actions
  21.             ->add(CRUD::PAGE_INDEXAction::DETAIL)
  22.             ->remove(Crud::PAGE_INDEXAction::NEW)
  23.             ->remove(Crud::PAGE_INDEXAction::DELETE)
  24.             ->remove(Crud::PAGE_INDEXAction::EDIT)
  25.             ->remove(Crud::PAGE_DETAILAction::DELETE)
  26.             ->remove(Crud::PAGE_DETAILAction::EDIT);
  27.     }
  28.     public function configureFields(string $pageName): iterable
  29.     {
  30.         $fields = [
  31.             TextField::new('name''Titre'),
  32.             AssociationField::new('category''Catégorie'),
  33.             AssociationField::new('range''Gamme'),
  34.             AssociationField::new('serie''Série'),
  35.             AssociationField::new('provider''Fournisseur'),
  36.         ];
  37.         if ($pageName == Crud::PAGE_DETAIL) {
  38.             $fields = [...$fields, ...[
  39.                 TextField::new('description'),
  40.                 TextField::new('required''Obligatoire'),
  41.                 TextField::new('options''Option'),
  42.                 TextField::new('additionalOptions''Options supplementaires'),
  43.                 TextField::new('referenceAFIMES''Référence AFIMES'),
  44.                 TextField::new('comment''Commentaire'),
  45.                 IntegerField::new('recommendedMarginRate''Taux de marge recommandé')
  46.                     ->formatValue(fn ($value) => $value "%"),
  47.                 IntegerField::new('providerDiscount''Remise fournisseur')
  48.                     ->formatValue(fn ($value) => $value "%"),
  49.                 TextField::new('unit''Unité'),
  50.                 CollectionField::new('productOptions''Options'),
  51.             ]];
  52.         }
  53.         return $fields;
  54.     }
  55. }