Skip to content

Commit 7680b8e

Browse files
committed
feature #26332 Add a data_help method in Form (mpiot, Nyholm)
This PR was merged into the 4.1-dev branch. Discussion ---------- Add a data_help method in Form | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26331 | License | MIT | Doc PR | symfony/symfony-docs#9361 Add a form_help method in twig to display a help message in form. A `help` keyword is added to all FormType to define the message. Commits ------- 585ca28b8a Add return type hint 859ee03785 Revert: remove comment line from twig templates d723756331 Fix some mistakes c74e0dc2da Use spaceless balises in Twig templates 8b937ff43f Try without try/catch 32bf1f68ad Test the renderHelp method in all Tests about help to skip them if necessary. 437b77e81a Skip renderHelp test as skipped if not override d84be700b2 Update composer files 075fcfd07c [FrameworkBundle] Add widgetAtt to formTable/form_row f1d13a860c Fix Fabpot.io 69ded67643 Added form_help on horizontal design and removed special variable fd53bc579a Enable aria-described in row for all Templates 98065d38b5 fabpot.io fix edb95f8e44 Use array long syntax aada72c5d4 Set help option on nul as default f948147e38 Rename help id (snake_case) 77fa3178bd Fix Test 30deaa9b28 PSR fix bf4d08c5ae Add aria-describedBy on input 1f3a15e33b Rename id 058489d7df Add an id to the help 6ea7a2054b Remove vars option from form_help ba798dfdf4 FrameworkBundle Tests 4f2581d7da Use array long syntax f15bc79df1 Fix coding standards c934e496d2 Add test without help set 8094804522 Add Tests 067c681580 Template for table, Foundation and Bootstrap 3 d3e3e492df Fix: check translation domain 2c2c04549f Adapt existant tests 831693ad45 Add trans filter e311838aed Remove raw filter for help 8b97c1b516 Use a shortcut to acces help var in Twig template 1b89f9d9dd Add a template fot div_layout c8914f591e Add a data_help method in Form
2 parents 474f593 + ee69e15 commit 7680b8e

File tree

8 files changed

+36
-7
lines changed

8 files changed

+36
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php if (!empty($help)): ?>
2+
<p id="<?php echo $view->escape($id); ?>_help" class="help-text"><?php echo $view->escape(false !== $translation_domain ? $view['translator']->trans($help, array(), $translation_domain) : $help); ?></p>
3+
<?php endif; ?>
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<div>
2-
<?php echo $view['form']->label($form) ?>
3-
<?php echo $view['form']->errors($form) ?>
4-
<?php echo $view['form']->widget($form) ?>
2+
<?php $widgetAttr = empty($help) ? array() : array('attr' => array('aria-describedby' => $id.'_help')); ?>
3+
<?php echo $view['form']->label($form); ?>
4+
<?php echo $view['form']->errors($form); ?>
5+
<?php echo $view['form']->widget($form, $widgetAttr); ?>
6+
<?php echo $view['form']->help($form); ?>
57
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>"<?php if ($disabled): ?> disabled="disabled"<?php endif ?>
22
<?php if ($required): ?> required="required"<?php endif ?>
3-
<?php echo $attr ? ' '.$view['form']->block($form, 'attributes') : '' ?>
3+
<?php echo $attr ? ' '.$view['form']->block($form, 'attributes') : '' ?>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<tr>
2+
<?php $widgetAttr = empty($help) ? array() : array('attr' => array('aria-describedby' => $id.'_help')); ?>
23
<td>
34
<?php echo $view['form']->label($form); ?>
45
</td>
56
<td>
67
<?php echo $view['form']->errors($form); ?>
7-
<?php echo $view['form']->widget($form); ?>
8+
<?php echo $view['form']->widget($form, $widgetAttr); ?>
9+
<?php echo $view['form']->help($form); ?>
810
</td>
911
</tr>

Templating/Helper/FormHelper.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,18 @@ public function label(FormView $view, $label = null, array $variables = array())
169169
return $this->renderer->searchAndRenderBlock($view, 'label', $variables);
170170
}
171171

172+
/**
173+
* Renders the help of the given view.
174+
*
175+
* @param FormView $view The parent view
176+
*
177+
* @return string The HTML markup
178+
*/
179+
public function help(FormView $view): string
180+
{
181+
return $this->renderer->searchAndRenderBlock($view, 'help');
182+
}
183+
172184
/**
173185
* Renders the errors of the given view.
174186
*

Tests/Templating/Helper/FormHelperDivLayoutTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
9191
return (string) $this->engine->get('form')->label($view, $label, $vars);
9292
}
9393

94+
protected function renderHelp(FormView $view)
95+
{
96+
return (string) $this->engine->get('form')->help($view);
97+
}
98+
9499
protected function renderErrors(FormView $view)
95100
{
96101
return (string) $this->engine->get('form')->errors($view);

Tests/Templating/Helper/FormHelperTableLayoutTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ protected function renderLabel(FormView $view, $label = null, array $vars = arra
9292
return (string) $this->engine->get('form')->label($view, $label, $vars);
9393
}
9494

95+
protected function renderHelp(FormView $view)
96+
{
97+
return (string) $this->engine->get('form')->help($view);
98+
}
99+
95100
protected function renderErrors(FormView $view)
96101
{
97102
return (string) $this->engine->get('form')->errors($view);

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"symfony/dom-crawler": "~3.4|~4.0",
4040
"symfony/polyfill-intl-icu": "~1.0",
4141
"symfony/security": "~3.4|~4.0",
42-
"symfony/form": "~3.4|~4.0",
42+
"symfony/form": "^4.1",
4343
"symfony/expression-language": "~3.4|~4.0",
4444
"symfony/process": "~3.4|~4.0",
4545
"symfony/security-core": "~3.4|~4.0",
@@ -65,7 +65,7 @@
6565
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
6666
"symfony/asset": "<3.4",
6767
"symfony/console": "<3.4",
68-
"symfony/form": "<3.4",
68+
"symfony/form": "<4.1",
6969
"symfony/property-info": "<3.4",
7070
"symfony/serializer": "<4.1",
7171
"symfony/stopwatch": "<3.4",

0 commit comments

Comments
 (0)