0

When I click delete next to a row in sonata admin it doesn't delete the row.

Say I'm trying to delete a press release, when I click the "delete" button on a press release the url changes to /pressreleases/3/delete and I get redirected back to my admin dashboard but the delete action doesn't happen. This happens for all my entities. However, my "edit" button works and allows me to edit a row.

Code example (scroll down to configureListFields):

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Form\FormMapper;


class AboutPressReleasesAdmin extends Admin
{

   // setup the default sort column and order
   protected $datagridValues = array(
      '_sort_order' => 'asc',
      '_sort_by' => 'id'
   );

   protected function configureFormFields(FormMapper $formMapper)
   {
      $formMapper
         ->add('title')
         ->add('text', 'textarea', array('required' => false, 'attr' => array('class' => 'tinymce', 'data-theme' => 'advanced')))
         ->add('created_at', 'date', array('required' => true))
      ;
   }

   protected function configureDatagridFilters(DatagridMapper $datagridMapper)
   {
      $datagridMapper
         ->add('title')
         ->add('text')
      ;
   }

   protected function configureListFields(ListMapper $listMapper)
   {
      $listMapper
         ->addIdentifier('title')
         ->add('text')
         ->add('created_at')
         ->add('updated_at')
         ->add('updated_by')
         // add custom action links
         ->add('_action', 'actions', array(
             'actions' => array(
                 'edit' => array(),
                 'delete' => array(),
             )
         ))
      ;
   }
}

What am I missing ?

MikeOscarEcho
  • 535
  • 2
  • 12
  • 27
  • I've had this problem before and it was due to some constraint not handled by the ORM. Are you able to delete the record with sql? – devilcius Dec 17 '14 at 18:25
  • @devilcius Yes I can delete it with sql. Do you remember how you solved it ? – MikeOscarEcho Dec 17 '14 at 21:11
  • My entity had a one-to-many relation field, is that your case? – devilcius Dec 17 '14 at 22:10
  • @devilcius Nope, doesn't work on any. I've got some that have no relationship and it doesn't delete the row when I click the delete button. The url changes to /entity/id/delete but I get redirected to the dashboard – MikeOscarEcho Dec 17 '14 at 22:31
  • @devilcius it seems the issue happens because I customized the sonata standard layout. So it takes me to the confirmation delete screen which I had overriden in the template with a welcome message. At least I know where the problem is, thanks! – MikeOscarEcho Dec 17 '14 at 22:54

0 Answers0