问题
I have a custom form type that defines some default attr
options:
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'invalid_message' => 'The selected image does not exist',
'attr'=>array(
'data-image-picker'=>'true',
'data-label'=>'Pick Image'
),
));
}
However when i use this custom form type the entire attr
array is replaced with what is defined.
$builder->add('logo','image_picker',array(
'attr'=>array(
'data-label'=>'Logo'
),
));
When the form is rendered it only has <input data-label="Logo" ...>
How do i get it so that those options will be merged not completly overridden?
回答1:
You can find these in the options
array passed as the second argument to the buildForm
method of your custom type. You would want to do something like this:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$options['attr']['data-label'] = 'Logo';
...
来源:https://stackoverflow.com/questions/27431524/default-options-for-symfony-2-forms-are-being-overridden-not-merged