creditUtils = $creditUtils; } protected function newAction() { $this->dispatch(EasyAdminEvents::PRE_NEW); $entity = $this->executeDynamicMethod('createNewEntity'); $easyadmin = $this->request->attributes->get('easyadmin'); $easyadmin['item'] = $entity; $this->request->attributes->set('easyadmin', $easyadmin); $fields = $this->entity['new']['fields']; $newForm = $this->executeDynamicMethod('createNewForm', [$entity, $fields]); $newForm->handleRequest($this->request); //ETAPE 1 Choix de l'utilisateur $user = $newForm->get('user')->getData(); if ($user == null) { $user = $this->getUserViaFirstStepForm($entity); } if (!$user instanceof UserInterface) return $user; else { $userMerchant = $this->creditUtils->activeCredit($user); return $this->redirectToRoute('easyadmin', [ 'action' => 'edit', 'entity' => $this->entity['name'], 'id' => $userMerchant->getId() ]); } } public function getUserViaFirstStepForm($entity) { $userClass = $this->em->getClassMetadata(UserInterface::class); $userChoiceForm = $this->createFormBuilder($entity) ->add('user', EntityType::class, array( 'class' => $userClass->name )) ->add('nextStep', SubmitType::class) ->getForm(); $userChoiceForm->handleRequest($this->request); if ($userChoiceForm->isSubmitted() && $userChoiceForm->isValid()) { return $userChoiceForm->get('user')->getData(); } $parameters = [ 'form' => $userChoiceForm->createView(), 'formView' => 'default', 'entity' => $entity, ]; return $this->executeDynamicMethod('renderTemplate', ['new', $this->entity['templates']['new'], $parameters]); } /** * The method that is executed when the user performs a 'show' action on an entity. * * @return Response */ public function showAction() { $this->dispatch(EasyAdminEvents::PRE_SHOW); $id = $this->request->query->get('id'); $easyadmin = $this->request->attributes->get('easyadmin'); $entity = $easyadmin['item']; $fields = $this->entity['show']['fields']; $deleteForm = $this->createDeleteForm($this->entity['name'], $id); $this->dispatch(EasyAdminEvents::POST_SHOW, [ 'deleteForm' => $deleteForm, 'fields' => $fields, 'entity' => $entity, ]); $parameters = [ 'entity' => $entity, 'fields' => $fields, 'delete_form' => $deleteForm->createView() ]; return $this->executeDynamicMethod('renderTemplate', ['show', $this->entity['templates']['show'], $parameters]); } /** * Réécriture de edit action pr rediriger vers le show */ public function editAction() { $id = $this->request->query->get('id'); $entity = $this->request->query->get('entity'); return $this->redirectToRoute('easyadmin', [ 'action' => 'show', 'entity' => $entity, 'id' => $id ]); } }