@@ -43,7 +43,6 @@ public function show(<?= $entity_class_name; ?> $<?= $entity_var_singular; ?>)
43
43
44
44
return $this->render('<?= $ route_name ; ?> /show.html.twig', [
45
45
'<?= $ entity_var_singular ; ?> ' => $<?= $ entity_var_singular ; ?> ,
46
- 'delete_form' => $deleteForm->createView(),
47
46
]);
48
47
}
49
48
@@ -100,7 +99,6 @@ public function edit(Request $request, <?= $entity_class_name; ?> $<?= $entity_v
100
99
return $this->render('<?= $ route_name ; ?> /edit.html.twig', [
101
100
'<?= $ entity_var_singular ; ?> ' => $<?= $ entity_var_singular ; ?> ,
102
101
'form' => $form->createView(),
103
- 'delete_form' => $deleteForm->createView(),
104
102
]);
105
103
}
106
104
@@ -115,31 +113,14 @@ public function edit(Request $request, <?= $entity_class_name; ?> $<?= $entity_v
115
113
*/
116
114
public function delete(Request $request, <?= $ entity_class_name ; ?> $<?= $ entity_var_singular ; ?> )
117
115
{
118
- $form = $this->createDeleteForm($<?= $ entity_var_singular ; ?> );
119
- $form->handleRequest($request);
120
-
121
- if ($form->isSubmitted() && $form->isValid()) {
122
- $em = $this->getDoctrine()->getManager();
123
- $em->remove($<?= $ entity_var_singular ; ?> );
124
- $em->flush();
116
+ if (!$this->isCsrfTokenValid('delete'.$<?= $ entity_var_singular ; ?> ->get<?= ucfirst ($ entity_identifier ); ?> (), $request->request->get('token'))) {
117
+ return $this->redirectToRoute('<?= $ route_name ; ?> _index');
125
118
}
126
119
127
- return $this->redirectToRoute('<?= $ route_name ; ?> _index');
128
- }
120
+ $em = $this->getDoctrine()->getManager();
121
+ $em->remove($<?= $ entity_var_singular ; ?> );
122
+ $em->flush();
129
123
130
- /**
131
- * Creates a form to delete a <?= $ entity_class_name ; ?> entity.
132
- *
133
- * @param <?= $ entity_class_name ; ?> $<?= $ entity_var_singular ; ?> The <?= $ entity_class_name ; ?> entity
134
- *
135
- * @return \Symfony\Component\Form\FormInterface The form
136
- */
137
- private function createDeleteForm(<?= $ entity_class_name ; ?> $<?= $ entity_var_singular ; ?> )
138
- {
139
- return $this->createFormBuilder()
140
- ->setAction($this->generateUrl('<?= $ route_name ; ?> _delete', ['<?= $ entity_identifier ; ?> ' => $<?= $ entity_var_singular ; ?> ->get<?= ucfirst ($ entity_identifier ); ?> ()]))
141
- ->setMethod('DELETE')
142
- ->getForm()
143
- ;
124
+ return $this->redirectToRoute('<?= $ route_name ; ?> _index');
144
125
}
145
126
}
0 commit comments