entityManager = $entityManager; $this->reminderFactory = $reminderFactory; $this->formFactory = $formFactory; $this->urlGenerator = $urlGenerator; $this->merchantResolver = $merchantResolver; $this->sectionResolver = $sectionResolver; $this->parameterBag = $parameterBag; } /** * @Route("/admin/reminder/modal", name="sov_admin_reminder_render_modal") */ public function renderModal(Request $request): Response { $crudAction = $request->get('crudAction'); $crudControllerFqcn = $request->get('crudControllerFqcn'); $entityId = $request->get('entityId'); $reminder = $this->createEntity($crudAction, $crudControllerFqcn, $entityId); $form = $this->formFactory->create( ReminderAdminFormType::class, $reminder, [ 'action' => $this->urlGenerator->generate( $this->parameterBag->get('app.reminder.route_new') ) ] ); return $this->render( '@LcSov/admin/reminder/form_modal.html.twig', [ 'form_reminder' => $form->createView() ] ); } /** * @Route("/admin/reminder/new", name="sov_admin_reminder_new") */ public function new(Request $request) { $reminder = $this->createEntity(); $form = $this->formFactory->create(ReminderAdminFormType::class, $reminder); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $reminder = $form->getData(); $this->entityManager->persist($reminder); $this->entityManager->flush(); $this->addFlash('success', 'Le pense-bête a bien été ajouté'); } return $this->redirect($request->headers->get('referer')); } public function createEntity(string $crudAction = null, string $crudControllerFqcn = null, int $entityId = null) { return $this->reminderFactory->create($crudAction, $crudControllerFqcn, $entityId); } /* public function renderTemplate($actionName, $templatePath, array $parameters = []) { if ($this->request->isXmlHttpRequest() && ($actionName == 'new' || $actionName == 'edit')) { $response['flashMessages'] = $this->utils->getFlashMessages(); $response['data'] = $this->render('@LcShop/backend/default/modal/edit_reminder.twig', $parameters)->getContent(); return new Response(json_encode($response)); } else { return parent::renderTemplate($actionName, $templatePath, $parameters); } } protected function redirectToReferrer() { $action = $this->request->query->get('action'); if ($action == 'new') { $this->utils->addFlash('success', 'success.reminder.add'); } elseif ($action == 'edit') { $this->utils->addFlash('success', 'success.reminder.edit'); } elseif ($action == ' setReminderDone') { $this->utils->addFlash('success', 'success.reminder.done'); } if ($this->request->isXmlHttpRequest()) { $response['flashMessages'] = $this->utils->getFlashMessages(); return new Response(json_encode($response)); } else { return parent::redirectToReferrer(); } } public function setReminderDoneAction() { $id = $this->request->query->get('id'); $done = $this->request->query->get('done'); $easyadmin = $this->request->attributes->get('easyadmin'); $reminder = $easyadmin['item']; $reminder->setDone($done); $this->em->persist($reminder); $this->em->flush(); return $this->redirectToReferrer(); }*/ }