Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the entity inside the buildForm method of a form

I'm trying to get the entity inside the own form. I lazy remember a getData() method, but it doesn't exist inside the form, and I can't remember how to use it.

Is there any way to get the entity inside the buildform method not using an event listener?

I mean, something like this:

 public function buildForm(FormBuilderInterface $builder, array $options)
   {
        /*some method to get the entity of the form such as getEntity????????*/
        $builder->add('field');
   }
like image 411
Angel Avatar asked Jun 27 '13 14:06

Angel


1 Answers

I found it:

public function buildForm(FormBuilderInterface $builder, array $options)    {         $entity = $builder->getData();         $builder->add('field');    } 
like image 64
Angel Avatar answered Oct 31 '22 10:10

Angel