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

Angel picture Angel · Jun 27, 2013 · Viewed 31.8k times · Source

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');
   }

Answer

Angel picture Angel · Jun 27, 2013

I found it:

public function buildForm(FormBuilderInterface $builder, array $options)
   {
        $entity = $builder->getData();
        $builder->add('field');
   }