To put in context there is an editor who can modify his information according to his id and his information must be validated by the admin before persisting in the database.
I have in mind to create a temporary table to store the information that the editor will modify and the admin can access his information via the interface of EasyAdmin then as soon as the admin validates the information it will persist in the original table.
I did not find in the documentation the way to recover the information of the form of the edit page.
I join the crud controller that I want to target:
class OperateurCrudController extends AbstractCrudController {
private $crudUrlGenerator;
private $adminContextProvider;
public function __construct(AdminUrlGenerator $adminUrlGenerator, AdminContextProvider $adminContextProvider)
{
$this->adminUrlGenerator = $adminUrlGenerator;
$this->adminContextProvider = $adminContextProvider;
}
public static function getEntityFqcn(): string
{
return Operateur::class;
}
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id')->hideOnForm(),
TextField::new('name', 'Nom'),
TextEditorField::new('description', 'Description')->hideOnIndex(),
TextareaField::new('address', 'Adresse'),
TextField::new('city', 'Ville')->hideOnIndex(),
TextField::new('postal_code', 'Code Postal')->hideOnIndex(),
TextField::new('email', 'Email'),
TelephoneField::new('phone', 'Téléphone'),
UrlField::new('website', 'Site Web')->hideOnIndex(),
TextEditorField::new('opening_hours', 'Horaires d\'Ouverture'),
NumberField::new('latitude', 'Latitude')->hideOnIndex()->setNumDecimals(15),
NumberField::new('longitude', 'Longitude')->hideOnIndex()->setNumDecimals(15),
TextField::new('slug', 'Slug')->hideOnIndex()->setPermission('ROLE_ADMIN'),
DateTimeField::new('created_at', 'Date Création')->onlyOnIndex(),
DateTimeField::new('updated_at', 'Date Modification')->onlyOnIndex(),
AssociationField::new('thematiques', 'Thématiques')
];
}
public function configureActions(Actions $actions): Actions
{
$batchAction = Action::new('approve', 'Approuver', 'fa fa-user-check')
->linkToUrl('approveOperators');
$updateOperator = Action::new('update', 'Enregistrer les modifications', 'fa fa-save')
->linkToCrudAction('saveOperator');
if($this->isGranted('ROLE_ADMIN')){
return $actions
->add(Crud::PAGE_INDEX, $batchAction)
->add(Crud:: PAGE_INDEX, Action::DETAIL)
->setPermission(Action::DELETE, 'ROLE_ADMIN')
->setPermission(Action::NEW, 'ROLE_ADMIN')
->setPermission(Action::EDIT, 'ROLE_ADMIN')
->setPermission($batchAction, 'ROLE_ADMIN');
}
if($this->isGranted('ROLE_EDITOR')){
return $actions
->add(Crud:: PAGE_INDEX, Action::DETAIL)
->add(Crud::PAGE_EDIT, $updateOperator)
->setPermission(Action::DELETE, 'ROLE_ADMIN')
->setPermission(Action::NEW, 'ROLE_ADMIN')
->setPermission($updateOperator, 'ROLE_EDITOR')
->disable( Action::SAVE_AND_RETURN, Action::SAVE_AND_CONTINUE);
}
}
public function approveOperators(): Response{
$this->addFlash('notice', '<span style="color: green"><i class="fa fa-check"></i>Modification effecuté </span>');
$url = $this->adminUrlGenerator
->setAction(Action::INDEX)
->generateUrl();
return $this->redirect($url);
}
public function saveOperator(){
//$this->addFlash('notice', '<span style="color: green"><i class="fa fa-check"></i>Modification pris en compte ! </span>');
//Create my own save button in page edit
}
public function configureCrud(Crud $crud): Crud
{
return $crud
->setEntityPermission('ROLE_EDITOR');
}
public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
$response = parent::createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters);
if(!$this->isGranted('ROLE_ADMIN')){
$response->where('entity.id = :id');
$response->setParameter('id', $this->getUser()->getOperateur());
}
return $response;
}
public function updateEntity(EntityManagerInterface $entityManager, $entityInstance): void
{
parent::updateEntity($entityManager, $entityInstance); // TODO: Change the autogenerated stub
}
Thank you for reading