1
votes

I am trying to use some bundles from sonata project for editing a 1:N association:

A MediaList can have many Media objects assigned. The doctrine configuration is correct, so is the configuration of MediaAdmin which is the admin class for my Media entity. The MediaList admin should embed the form for my Media and allow adding / removing items to the list:

protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper->add('media', 'sonata_type_collection',
            [
                'by_reference' => false,
            ],
            [
                'edit' => 'inline',
                'inline' => 'table'
            ]);
    }

In symfony 3, the support for string formtypes such as "sonata_type_collection" has been dropped. However, the SonataCoreBundle adds some functionality that should re-enable this feature (see documentation 3.1).

Unfortunately this is not working for me and I get an InvalidArgumentException (Could not load type "sonata_type_collection")

  • I made sure FormHelper::registerFormTypeMapping in SonataCoreBundle and SonataAdminBundle gets called with a breakpoint and debugging.
  • I tried using the FQCN instead (Sonata\CoreBundle\Form\Type\CollectionType) but sonata then uses sonata_type_admin internally which fails when I press the "add" button
  • It worked a few days ago and fails since I ran composer update without changing anything in my composer.json

So how do I use these form types in Symfony 3.X? Is there any additional config needed?

My composer.json (not all entries, but I think the most relevant):

"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"sonata-project/admin-bundle": "^3.20.1",
"sonata-project/doctrine-orm-admin-bundle": "^3.1",
"symfony/symfony": "3.3.2",
1

1 Answers

0
votes

I found a configuration that is working for me. I had minimum-stability in my composer.json set to dev. After changing it to stable and update it works again.