Skip to content
Advertisement

Symfony 4: Use existing form type class in Sonata’s configureFormFields method

I know I can pull individual form elements from the type’s builder into the form mapper as described in the documentation:

You can add Symfony FormBuilderInterface instances to the FormMapper. This allows you to re-use a model form type. When adding a field using a FormBuilderInterface, the type is guessed.

Given you have a PostType like this:

JavaScript

you can reuse it like this:

JavaScript

However, this feels clunky if all you want is for Sonata to use that exact type as is.

I was therefore wondering if there is a shorthand that tells sonata to simply use the entire form type as is.

Something like:

JavaScript

Advertisement

Answer

Maybe the shorter version using inherit_data might be what you are looking for.

https://symfony.com/doc/current/form/inherit_data_option.html

From: How to inherit FormType in Sonata Admin?

With the Post example

JavaScript

Using PostAdmin (and PostType) to map a child record in a 1:m relationship works too, but has problems with inline options and the table view does not seem to render it in separate columns as expected.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement