Search code examples
phpsymfonysymfony-formssonata-adminsonata

Display collection form on page load in Sonata Admin Bundle


Is there an option or a known way to display collection form on page load instead of clicking on "add" button in order to display it ?

I trigger a click event on page load but its not the expected behavior..

Any help would be much appreciated.


Solution

  • Alright, I achieved what I wanted by setting a default collection array on my form field, each Entity object in array imbricates a form, since I needed to display 3 form on page load I instanciated 3 entity, quite logic when I think of it now but a dedicated option could be nice though.

    ->add('details', CollectionType::class, [
                'data' => [new OfferDetail(), new OfferDetail(), new OfferDetail()],
                'label' => false,
                'required' => true,
                'type_options' => [
                    'delete' => false,
                ],
            ], [
                'edit' => 'inline',
                'inline' => 'table'
            ])