Skip to content

Commit

Permalink
Add a delete action
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Rabaix committed Sep 4, 2011
1 parent 1e46436 commit 40d97a5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Controller/CRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ public function batchActionDelete($query)
return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
}

/**
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException|\Symfony\Component\Security\Core\Exception\AccessDeniedException
* @param $id
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response|\Symfony\Component\HttpFoundation\RedirectResponse
*/
public function deleteAction($id)
{
if (false === $this->admin->isGranted('DELETE')) {
Expand All @@ -184,10 +189,17 @@ public function deleteAction($id)
throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
}

$this->admin->delete($object);
$this->get('session')->setFlash('sonata_flash_success', 'flash_delete_success');
if ($this->getRequest()->getMethod() == 'DELETE') {
$this->admin->delete($object);
$this->get('session')->setFlash('sonata_flash_success', 'flash_delete_success');

return new RedirectResponse($this->admin->generateUrl('list'));
return new RedirectResponse($this->admin->generateUrl('list'));
}

return $this->render('SonataAdminBundle:CRUD:delete.html.twig', array(
'object' => $object,
'action' => 'delete'
));
}

/**
Expand Down
4 changes: 4 additions & 0 deletions Resources/views/CRUD/base_edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ file that was distributed with this source code.
{% if admin.id(object) %}
<input type="submit" name="btn_update_and_edit" value="{% trans from 'SonataAdminBundle' %}btn_update_and_edit_again{% endtrans %}"/>
<input type="submit" name="btn_update_and_list" value="{% trans from 'SonataAdminBundle' %}btn_update_and_return_to_list{% endtrans %}"/>

{% if admin.isGranted('DELETE') %}
<a href="{{ admin.generateObjectUrl('delete', object) }}">{% trans from 'SonataAdminBundle' %}link_delete{% endtrans %}</a>
{% endif %}
{% else %}
<input type="submit" name="btn_create_and_edit" value="{% trans from 'SonataAdminBundle' %}btn_create_and_edit_again{% endtrans %}"/>
<input type="submit" name="btn_create_and_create" value="{% trans from 'SonataAdminBundle' %}btn_create_and_create_a_new_one{% endtrans %}"/>
Expand Down
44 changes: 44 additions & 0 deletions Resources/views/CRUD/delete.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{#
This file is part of the Sonata package.
(c) Thomas Rabaix <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}

{% extends base_template %}

{% block actions %}
<div class="sonata-actions">
<ul>
{% if admin.hasRoute('edit') and admin.isGranted('EDIT')%}
<li class="sonata-action-element"><a href="{{ admin.generateObjectUrl('edit', object) }}">{% trans from 'SonataAdminBundle' %}link_action_edit{% endtrans %}</a></li>
{% endif %}

{% if admin.hasRoute('create') and admin.isGranted('CREATE')%}
<li class="sonata-action-element"><a href="{{ admin.generateUrl('create') }}">{% trans from 'SonataAdminBundle' %}link_action_create{% endtrans %}</a></li>
{% endif %}
</ul>
</div>
{% endblock %}

{% block side_menu %}{{ admin.sidemenu(action)|knp_menu_render('list') }}{% endblock %}

{% block content %}
<div class="sonata-ba-delete">

<h1>{% trans from 'SonataAdminBundle' %}title_delete{% endtrans %}</h1>

{% trans with {'%object%': object} from 'SonataAdminBundle' %}message_delete_confirmation{% endtrans %}

<form method="POST" action="{{ admin.generateObjectUrl('delete', object) }}">
<input type="hidden" value="DELETE" name="_method" />

<input type="submit" value="{% trans from 'SonataAdminBundle' %}btn_delete{% endtrans %}" />
</form>

</div>
{% endblock %}

0 comments on commit 40d97a5

Please sign in to comment.