Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable 'add' with sonata_type_collection in SonataAdminBundle forms

Does anyone out there know how I can get rid of the green pluses that allow adding a new item to a collection in the sonata admin forms? The native collectiontype has allow_add & allow_delete, but sonata_type_collection doesn't seem to notice those options.

I have tried the following:

    ->add('store_orders', 'sonata_type_collection', array(), array(
      'type_options' => array('allow_add' => false),
    ))

which has no effect

    ->add('store_orders', 'sonata_type_collection', array(
      'allow_add' => false
    ))

which gives an error 'The option "allow_add" does not exist'

    ->add('store_orders', 'sonata_type_collection', array(
      'type_options' => array('allow_add' => false)
    ))

which also gives an error 'The option "allow_add" does not exist'

I'd also like to remove the delete checkboxes next to each item in the collection. I presume the answer to that lies in a similar area.

Any assistance would be greatly appreciated.

like image 455
user1207727 Avatar asked Dec 13 '22 04:12

user1207727


1 Answers

Try this

->add('store_orders', 'sonata_type_collection', array(
      'btn_add' => false
    ))

When you add a collection to Sonata admin forms, by default an "Add New" button is displayed, to prevent the "Add New" Button or "+" from displaying, set the add_btn key to FALSE in the array, which is the third parameter in the add function.

like image 158
Albert St Clair Avatar answered Dec 17 '22 05:12

Albert St Clair