1 What i want to do is add custom (option is 'angular' in this case)option to my form widget template:
{%- block widget_attributes -%}
id="{{ id }}" name="{{ full_name }}"
{%- if angular %} ng-model="{{ full_name }}"{% endif -%}
....
{%- if intention %} {{ intention }}{% endif -%}
{%- if read_only %} readonly="readonly"{% endif -%}
.....
{%- endblock widget_attributes -%}
I wand to decide about form has it option or no in my CustomFormType. But i can't achieve it. I tried different method.
Is it possible to add custom option to the main form?
I know that there are a lot of tutorials showing how to pass custom options in child element, e.g http://symfony.com/doc/current/cookbook/form/create_form_type_extension.html
I investigated core of form component and there are class
namespace Symfony\Component\Form\Extension\Core\Type;
class FormType extends BaseType{}
which has method build View
public function buildView(FormView $view, FormInterface $form, array $options)
{
.....
$view->vars = array_replace($view->vars, array(
'read_only' => $readOnly,
'errors' => $form->getErrors(),
'valid' => $form->isSubmitted() ? $form->isValid() : true,
'value' => $form->getViewData(),
'data' => $form->getNormData(),
'required' => $form->isRequired(),
'max_length' => isset($options['attr']['maxlength']) ? $options['attr']['maxlength'] : null, // Deprecated
'pattern' => isset($options['attr']['pattern']) ? $options['attr']['pattern'] : null, // Deprecated
'size' => null,
'label_attr' => $options['label_attr'],
'compound' => $form->getConfig()->getCompound(),
'method' => $form->getConfig()->getMethod(),
'action' => $form->getConfig()->getAction(),
'submitted' => $form->isSubmitted(),
));
}
Above symfony define base options. I can access these options globally in form template, but i can't find the way to add my own.