<?php
namespace App\Controller\Admin;
use App\Entity\Product;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class ProductCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Product::class;
}
public function configureActions(Actions $actions): Actions
{
return $actions
->add(CRUD::PAGE_INDEX, Action::DETAIL)
->remove(Crud::PAGE_INDEX, Action::NEW)
->remove(Crud::PAGE_INDEX, Action::DELETE)
->remove(Crud::PAGE_INDEX, Action::EDIT)
->remove(Crud::PAGE_DETAIL, Action::DELETE)
->remove(Crud::PAGE_DETAIL, Action::EDIT);
}
public function configureFields(string $pageName): iterable
{
$fields = [
TextField::new('name', 'Titre'),
AssociationField::new('category', 'Catégorie'),
AssociationField::new('range', 'Gamme'),
AssociationField::new('serie', 'Série'),
AssociationField::new('provider', 'Fournisseur'),
];
if ($pageName == Crud::PAGE_DETAIL) {
$fields = [...$fields, ...[
TextField::new('description'),
TextField::new('required', 'Obligatoire'),
TextField::new('options', 'Option'),
TextField::new('additionalOptions', 'Options supplementaires'),
TextField::new('referenceAFIMES', 'Référence AFIMES'),
TextField::new('comment', 'Commentaire'),
IntegerField::new('recommendedMarginRate', 'Taux de marge recommandé')
->formatValue(fn ($value) => $value . "%"),
IntegerField::new('providerDiscount', 'Remise fournisseur')
->formatValue(fn ($value) => $value . "%"),
TextField::new('unit', 'Unité'),
CollectionField::new('productOptions', 'Options'),
]];
}
return $fields;
}
}