access underlying entity in symfony2 form builder

forms, symfony

Solution

praxmatig pointed me in the right direction, the solution is even easier:

the underlying entity is automatically available as an option named "data", so you can do:

public function buildForm(FormBuilderInterface $builder, array $options) {
   // whatever

   if (isset($options['data'])) {
      switch ($options['data']->getSomeVariable()) {
      // whatever
      }
   }

   // whatever
}

Problem

I'm looking for a way to access the data class entity in a symfony2 form builder class. The reason I need this is because the text on the submit button should change depending on a value of this entity (a value the user cannot change in the form). so basically I want to do: ``` if ($this->entity->getVariable() == xxx) { // do something } else { // do something else } ``` inside the form builder class

Original source