R
R
Radarchik2018-03-02 02:58:44
symfony
Radarchik, 2018-03-02 02:58:44

How to overwrite a variable from its own field type?

I create my own field type inherited from CheckBoxType
getParent = CheckboxType::class
getBlockPrefix = mycheckbox
In the options I start a new variable my_label
In the field template:

{% block mycheckbox_widget %}
  {% set label = my_label %}
  {{ block('checkbox_widget') }}
{% endblock %}

But my inscription is not displayed in the checkbox, what should I do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2018-03-02
@Radarchik

Options are not available in view. To do this, add the following code:
CheckBoxType:

/**
 * @inheritDoc
 */
public function buildView(FormView $view, FormInterface $form, array $options)
{
    $view->vars['my_label'] = $options['my_label'];
    // Либо сразу
    // $view->vars['label'] = $options['my_label'];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question