Ejemplo n.º 1
0
 /**
  * Deletes a Contact entity.
  *
  * @Route("/{id}", name="crud_contact_delete")
  * @Method("DELETE")
  * @param Request $request
  * @param Contact $contact
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function deleteAction(Request $request, Contact $contact = null)
 {
     if ($contact === null) {
         return $this->render('contact/not_found.html.twig');
     }
     $currentUser = $this->get('security.token_storage')->getToken()->getUser();
     if ($currentUser === $contact->getOwner()) {
         $form = $this->createDeleteForm($contact);
         $form->handleRequest($request);
         if ($form->isSubmitted() && $form->isValid()) {
             $em = $this->getDoctrine()->getManager();
             $em->remove($contact);
             $em->flush();
         }
         return $this->redirectToRoute('crud_contact_index');
     } else {
         return $this->render('contact/unauthorized.html.twig');
     }
 }