GBRocks
GBRocks

Reputation: 698

Remove delete checkbox Sonata Admin Bundle

I am using Sonata admin bundle and I have embedded admins. The child entities are listed as a table structure. I have removed the delete route for the child admin. But still delete checkbox is coming when the child is embedded.

i.e I have a Product table and a price table. I am embedding the price table in the product table. In the price table I am able to remove the delete button. But when embedded, the delete checkbox is appearing in the product table and if checked and updated, the row gets deleted. Could anyone of you please help me remove the delete checkbox..?? Thanks in advance

Upvotes: 4

Views: 3626

Answers (3)

Saerdn
Saerdn

Reputation: 228

The original answer didn't work for me (probably because of newer Sonata Admin version). That is what worked for me:

->add(
   'field_name',
   CollectionType::class,
   [
     'required' => false,
     'type' => AdminType::class,
     'type_options' => [
       'delete' => false
     ]
   ],
   [
     'edit' => 'inline',
     'inline' => 'table',
     'admin_code' => 'admin.entity'
   ]
 )

Upvotes: 0

GBRocks
GBRocks

Reputation: 698

The type option can do the job for embedded admins like below.

$formMapper
    ->add('field_name', 'sonata_type_collection',
                array('type_options' => array('delete' => false)),
                array(
                    'edit'   => 'inline',
                    'inline' => 'table'
                ))
        ;

Upvotes: 7

Pascal
Pascal

Reputation: 1284

in your admin class, you can try :

$formMapper
        ->remove('_delete')

Upvotes: -1

Related Questions