remove delete actions & form in controller

This commit is contained in:
Julien Fastré 2015-10-02 23:04:56 +02:00
parent bebee4fbeb
commit 216d0c55be

View File

@ -101,11 +101,8 @@ class ActivityReasonController extends Controller
throw $this->createNotFoundException('Unable to find ActivityReason entity.');
}
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillActivityBundle:ActivityReason:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
));
}
@ -124,12 +121,10 @@ class ActivityReasonController extends Controller
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('ChillActivityBundle:ActivityReason:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
'edit_form' => $editForm->createView()
));
}
@ -165,7 +160,6 @@ class ActivityReasonController extends Controller
throw $this->createNotFoundException('Unable to find ActivityReason entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
@ -177,48 +171,7 @@ class ActivityReasonController extends Controller
return $this->render('ChillActivityBundle:ActivityReason:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
'edit_form' => $editForm->createView()
));
}
/**
* Deletes a ActivityReason entity.
*
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillActivityBundle:ActivityReason')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find ActivityReason entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('chill_activity_activityreason'));
}
/**
* Creates a form to delete a ActivityReason entity by id.
*
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm($id)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('chill_activity_activityreason_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
}