I have a Formtype. In this Formtype I get over the options-Array in the buildForm function a key additionalName. I want to add this value to the FormType Name (in Symfony3 BlockPrefix). But how can I set this?
class AdultType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$additionalName = $options['additionalName'];
$builder
->add('account', TextType::class,array(
'label' => 'account',
'required' => false,
))
;
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'My\Bundle\WebsiteBundle\Model\Adult',
'csrf_protection' => true,
'cascade_validation' => true,
'name' => ""
));
}
/**
* @return string
*/
public function getBlockPrefix()
{
//Here I need the $options['additionalName']
return 'my_bundle_websitebundle_adult_'.$options['additionalName'];
}
I tried allready to set a variable private $additionalName; on the top of the class, set it in the buildForm function and get access to it with $this->additionalName in the getBlockPrefix Function. But the value in getBlockPrefix is empty. SO I think the getBlockPrefix is called before the buildForm.
The Type is beeing called from another form:
$builder->add('adult', AdultType::class, array(
'additionalName' => $options['name']
));
Thanks for any help!