This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

[SonataAdmin] Use $formMapper inside event

Discuss Symfony 2 bundles here

[SonataAdmin] Use $formMapper inside event

by makeron » Thu Jun 19, 2014 8:43 am

Hello,

I am trying to use the sonataAdmin $formMapper inside an event. Here is the code:

Code: Select all
$formModifier = function (FormInterface $form, DestinationType $type, FormMapper $formMapper) {

            if ($type->getName() == 'City') {
                $formMapper->add(
                    'name',
                    'text'
                );
            }
        };

        $builder->addEventListener(
            FormEvents::PRE_SET_DATA,
            function (FormEvent $event) use ($formModifier, $em, $formMapper) {
                $data = $event->getData();           
                 
                $formModifier($event->getForm(), $type, $formMapper);               
            }
        );


The issue is that the field never gets displayed but when using $form object instead of $formMapper it works. Also if I move formMapper outside the event also it works.
Can you please give me a solution?

Regards
makeron
Junior Member
 
Posts: 1
Joined: Thu Jun 19, 2014 7:35 am

Re: [SonataAdmin] Use $formMapper inside event

by caponica » Tue Oct 07, 2014 10:28 pm

Hi, I don't have a solution to this but I do have the same problem... will post here if I find a solution!
User avatar
caponica
Senior Member
 
Posts: 121
Joined: Mon Mar 17, 2008 11:25 am
Location: London

Re: [SonataAdmin] Use $formMapper inside event

by caponica » Wed Oct 08, 2014 12:19 am

Still no progress with this one so I posted a question on Stack:
http://stackoverflow.com/questions/26246192/correct-way-to-use-formevents-to-customise-fields-in-sonataadmin

If I get an answer there I will try to update here as well.
User avatar
caponica
Senior Member
 
Posts: 121
Joined: Mon Mar 17, 2008 11:25 am
Location: London

Re: [SonataAdmin] Use $formMapper inside event

by caponica » Wed Oct 08, 2014 10:59 pm

I think I've got it working - take a look at the code fragment on Stack if you come across this thread in future!
User avatar
caponica
Senior Member
 
Posts: 121
Joined: Mon Mar 17, 2008 11:25 am
Location: London