Ejemplo n.º 1
0
 /**
  * @param Request $request
  * @param Membership $membership
  * @param Document $document
  * @return Response
  *
  * @Route("/member/membership/{membership}/document/{document}/delete",
  *     name="app_member_membership_document_delete",
  *     methods={"GET","POST"},
  *     requirements={"membership"="\d+","document"="\d+"})
  */
 public function documentDeleteAction(Request $request, Membership $membership, Document $document)
 {
     // Delete form
     $formDelete = $this->createForm(DocumentDeleteType::class, $document);
     $formDelete->handleRequest($request);
     if ($formDelete->isSubmitted() && $formDelete->isValid()) {
         // Delete document
         if ($document == $membership->getMedicalCertificate()) {
             $membership->setMedicalCertificate(null);
         } elseif ($document == $membership->getRegistrationForm()) {
             $membership->setRegistrationForm(null);
         }
         $dm = $this->get('app.document_manager');
         $dm->delete($document);
         // Flash message
         $this->addFlash('success', $this->get('translator')->trans('document_delete.success.deleted', array(), 'member'));
         // Redirect
         return $this->redirectToRoute('app_member_membership_edit', ['membership' => $membership->getId()]);
     }
     // Render
     return $this->render('member/membership/document/delete.html.twig', ['document' => $document, 'formDelete' => $formDelete->createView(), 'membership' => $membership]);
 }