A
A
Alexey Anisimov2017-04-19 14:30:06
symfony
Alexey Anisimov, 2017-04-19 14:30:06

How to make 2 entity editing pages with different forms in SonataAdminBundle?

Good afternoon.
How to make 2 entity editing pages with different forms in SonataAdminBundle?
For example, on one page, all fields of the User entity are edited (full editing), and on the other, only some (short editing).
Is there any way to set the context?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
koninka, 2017-04-19
@AnisimovAM

You can resolve the content at the request level with an additional parameter (a-la editing_context=simple) and configureFormFieldsget it from the request in the method

$this->getRequest()->get('editing_context', $fallbackContext)

and already on its basis to determine which fields to add to the form.
Moreover, the sonata forms of the mapper have convenient helpers ifTrue, ifFalseand you can write beautiful code without any snot like:
$formMapper
    ->add('name')
    ->ifTrue($editingContext === 'full')
        ->add('someField1')
        ->add('someField2')
    ->ifEnd()
    ->add('createdAt')
;

A
Alexey Pavlov, 2017-04-19
@lexxpavlov

Just create two different admin entities associated with the same entity.
For example, this is how it is done in my bundle in the config , and here the entries are shown by condition .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question