i have the following form where i would like to pass some objects to the inner forms in order to populate them with data when being edited:
public function __construct( $em, $id )
{
$this->_em = $em;
}
public function buildForm( \Symfony\Component\Form\FormBuilderInterface $builder, array $options )
{
$builder->add( 'accessInfo', new AccessInfoType( $this->_em, $options[ 'entities' ][ 'user' ] ) , array(
'attr' => array( 'class' => 'input-medium' ),
'required' => false,
'label' => false
)
);
$builder->add( 'profileInfo', new ProfileInfoType( $this->_em, $options[ 'entities' ][ 'profile' ] ) , array(
'required' => false,
'label' => false
)
);
}
public function setDefaultOptions( \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver )
{
$resolver->setDefaults( $this->getDefaultOptions( array() ) );
return $resolver->setDefaults( array( ) );
}
/**
* {@inheritDoc}
*/
public function getDefaultOptions( array $options )
{
$options = parent::getDefaultOptions( $options );
$options[ 'entities' ] = array();
return $options;
}
public function getName()
{
return 'UserType';
}
which i instantiate with the following code:
$form = $this->createForm( new UserType( $em ), null, array( 'entities' => array( 'user' => $userObj, 'profile' => $profileObj ) ) );
Once i get, via the constructor, the object containing the needed data does anyone know how could i bind that object to the form?
class ProfileInfoType extends AbstractType
{
private $_em;
public function __construct( $em, $dataObj )
{
$this->_em = $em;
$this->_dataObj = $dataObj;
}
Thanks in advanced!