Skip to content

Commit c8914f5

Browse files
Mathieu Piotmpiot
authored andcommitted
Add a data_help method in Form
1 parent d5a55a5 commit c8914f5

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

src/Symfony/Bridge/Twig/Extension/FormExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function getFunctions()
4747
new TwigFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
4848
new TwigFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
4949
new TwigFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
50+
new TwigFunction('form_help', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
5051
new TwigFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
5152
new TwigFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
5253
new TwigFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@
260260
<{{ element|default('div') }} class="form-group">
261261
{{- form_label(form) -}}
262262
{{- form_widget(form) -}}
263+
{{- form_help(form) -}}
263264
</{{ element|default('div') }}>
264265
{%- endblock form_row %}
265266

@@ -276,3 +277,11 @@
276277
</span>
277278
{%- endif %}
278279
{%- endblock form_errors %}
280+
281+
{# Help #}
282+
283+
{% block form_help -%}
284+
{% if form.vars.help is not empty %}
285+
<small class="form-text text-muted">{{ form.vars.help|raw }}</small>
286+
{% endif %}
287+
{%- endblock form_help %}

src/Symfony/Bridge/Twig/UndefinedCallableHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class UndefinedCallableHandler
3434
'form_widget' => 'form',
3535
'form_errors' => 'form',
3636
'form_label' => 'form',
37+
'form_help' => 'form',
3738
'form_row' => 'form',
3839
'form_rest' => 'form',
3940
'form' => 'form',

src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
8989
'required' => $form->isRequired(),
9090
'size' => null,
9191
'label_attr' => $options['label_attr'],
92+
'help' => $options['help'],
9293
'compound' => $formConfig->getCompound(),
9394
'method' => $formConfig->getMethod(),
9495
'action' => $formConfig->getAction(),
@@ -178,10 +179,12 @@ public function configureOptions(OptionsResolver $resolver)
178179
'attr' => array(),
179180
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
180181
'upload_max_size_message' => $uploadMaxSizeMessage, // internal
182+
'help' => '',
181183
));
182184

183185
$resolver->setAllowedTypes('label_attr', 'array');
184186
$resolver->setAllowedTypes('upload_max_size_message', array('callable'));
187+
$resolver->setAllowedTypes('help', 'string');
185188
}
186189

187190
/**

0 commit comments

Comments
 (0)