I have generated the CRUD of an entity, getting the following default actions:
if you only want to have as much delete buttons as items in your index here's how to easily do it.
In the indexAction, add the following loop and don't forget to pass the parameter to the view.
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('FooBundle:Link')->findAll();
$deleteForms = array();
foreach ($entities as $entity) {
$deleteForms[$entity->getId()] = $this->createDeleteForm($entity->getId())->createView();
}
return array(
'entities' => $entities,
'deleteForms' => $deleteForms,
);
}
Basicaly I just loop over all my entities and create the corresponding delete form using the built-in method generated by the crud, storing each form in an array and passing it to the view.
Then in the view, just add the form already available in the edit.html.twig generated view and edit the form_widget's parameter:
<form action="{{ path('foo_delete', { 'id': entity.id }) }}" method="post">
<input type="hidden" name="_method" value="DELETE" />
{{ form_widget(deleteForms[entity.id]) }}
<button type="submit" class="btn btn-small">
<i class="icon-trash"></i>
{{ 'links.admin.form.delete' | trans({}, 'FooBundle') }}
</button>
</form>