How to rewrite a variable from your field type?

Create a field type that inherits from CheckBoxType
getParent = CheckboxType::class
getBlockPrefix = mycheckbox
In the options, make a new variable my_label

In the template field:
{% block mycheckbox_widget %}
 {% set label = my_label %}
 {{ block('checkbox_widget') }}
{% endblock %}

But my writing is not displayed in the checkbox, how to be?
June 7th 19 at 14:55
2 answers
June 7th 19 at 14:57
Options are not available in the view. To do this, add the following code:
 * @inheritDoc
public function buildView(FormView $view, FormInterface $form, array $options)
 $view->vars['my_label'] = $options['my_label'];
 // Or just
 // $view->vars['label'] = $options['my_label'];
My writing is passed to my widget, but in the "checkbox_widget" is not displayed. - nikita.Stracke commented on June 7th 19 at 15:00
, label, and must not displayed in a widget block. You need to override mycheckbox_label - Candace_Bogisich commented on June 7th 19 at 15:03
understood? If label is not an example and do I need to replace it (but why?) it is better to use the example above
$view->vars['label'] = $options['my_label'];
And so widget does not include the labels (this is just the input tag), respectively, and is not displayed.

To override any of the wrappers/containers, where you want to display these widgets often need to override form_row - Candace_Bogisich commented on June 7th 19 at 15:06
, it was necessary to change the label in twig template, because there are in addition other actions of course, with them are made. - nikita.Stracke commented on June 7th 19 at 15:09
June 7th 19 at 14:59
{% block mycheckbox_widget %}
 {{ block('checkbox_widget') }}
{% endblock %}

{% block mycheckbox_label %}
 {% set label = my_label %}
 {{ block('checkbox_label') }}
{% endblock %}

Find more questions by tags TwigSymfony