Skip to content

Commit a4c1c7a

Browse files
mpiotxabbuh
authored andcommitted
Add help_attr
1 parent 036c679 commit a4c1c7a

8 files changed

+91
-5
lines changed

Resources/views/Form/bootstrap_3_layout.html.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@
177177

178178
{% block form_help -%}
179179
{%- if help is not empty -%}
180-
<span id="{{ id }}_help" class="help-block">
180+
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' help-block')|trim}) -%}
181+
182+
<span id="{{ id }}_help" {% for attrname, attrvalue in help_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
181183
{%- if translation_domain is same as(false) -%}
182184
{{- help -}}
183185
{%- else -%}

Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@
297297

298298
{% block form_help -%}
299299
{%- if help is not empty -%}
300-
<small id="{{ id }}_help" class="form-text text-muted">
300+
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' form-text text-muted')|trim}) -%}
301+
302+
<small id="{{ id }}_help" {% for attrname, attrvalue in help_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
301303
{%- if translation_domain is same as(false) -%}
302304
{{- help -}}
303305
{%- else -%}

Resources/views/Form/form_div_layout.html.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@
291291

292292
{% block form_help -%}
293293
{%- if help is not empty -%}
294-
<p id="{{ id }}_help" class="help-text">
294+
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' help-text')|trim}) -%}
295+
296+
<p id="{{ id }}_help" {% for attrname, attrvalue in help_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
295297
{%- if translation_domain is same as(false) -%}
296298
{{- help -}}
297299
{%- else -%}

Tests/Extension/AbstractBootstrap3LayoutTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,26 @@ public function testHelp()
120120
);
121121
}
122122

123+
public function testHelpAttr()
124+
{
125+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
126+
'help' => 'Help text test!',
127+
'help_attr' => array(
128+
'class' => 'class-test',
129+
),
130+
));
131+
$view = $form->createView();
132+
$html = $this->renderHelp($view);
133+
134+
$this->assertMatchesXpath($html,
135+
'/span
136+
[@id="name_help"]
137+
[@class="class-test help-block"]
138+
[.="[trans]Help text test![/trans]"]
139+
'
140+
);
141+
}
142+
123143
public function testErrors()
124144
{
125145
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');

Tests/Extension/AbstractBootstrap4LayoutTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ public function testHelp()
177177
);
178178
}
179179

180+
public function testHelpAttr()
181+
{
182+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
183+
'help' => 'Help text test!',
184+
'help_attr' => array(
185+
'class' => 'class-test',
186+
),
187+
));
188+
$view = $form->createView();
189+
$html = $this->renderHelp($view);
190+
191+
$this->assertMatchesXpath($html,
192+
'/small
193+
[@id="name_help"]
194+
[@class="class-test form-text text-muted"]
195+
[.="[trans]Help text test![/trans]"]
196+
'
197+
);
198+
}
199+
180200
public function testErrors()
181201
{
182202
$form = $this->factory->createNamed('name', TextType::class);

Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,26 @@ public function testMoneyWidgetInIso()
190190
$this->assertSame('&euro; <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
191191
}
192192

193+
public function testHelpAttr()
194+
{
195+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
196+
'help' => 'Help text test!',
197+
'help_attr' => array(
198+
'class' => 'class-test',
199+
),
200+
));
201+
$view = $form->createView();
202+
$html = $this->renderHelp($view);
203+
204+
$this->assertMatchesXpath($html,
205+
'/p
206+
[@id="name_help"]
207+
[@class="class-test help-text"]
208+
[.="[trans]Help text test![/trans]"]
209+
'
210+
);
211+
}
212+
193213
protected function renderForm(FormView $view, array $vars = array())
194214
{
195215
return (string) $this->renderer->renderBlock($view, 'form', $vars);

Tests/Extension/FormExtensionTableLayoutTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,26 @@ public function testStartTagHasActionAttributeWhenActionIsZero()
7676
$this->assertSame('<form name="form" method="get" action="0">', $html);
7777
}
7878

79+
public function testHelpAttr()
80+
{
81+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, array(
82+
'help' => 'Help text test!',
83+
'help_attr' => array(
84+
'class' => 'class-test',
85+
),
86+
));
87+
$view = $form->createView();
88+
$html = $this->renderHelp($view);
89+
90+
$this->assertMatchesXpath($html,
91+
'/p
92+
[@id="name_help"]
93+
[@class="class-test help-text"]
94+
[.="[trans]Help text test![/trans]"]
95+
'
96+
);
97+
}
98+
7999
protected function renderForm(FormView $view, array $vars = array())
80100
{
81101
return (string) $this->renderer->renderBlock($view, 'form', $vars);

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/asset": "~3.4|~4.0",
2424
"symfony/dependency-injection": "~3.4|~4.0",
2525
"symfony/finder": "~3.4|~4.0",
26-
"symfony/form": "^4.1.5",
26+
"symfony/form": "^4.2",
2727
"symfony/http-foundation": "~3.4|~4.0",
2828
"symfony/http-kernel": "~3.4|~4.0",
2929
"symfony/polyfill-intl-icu": "~1.0",
@@ -42,7 +42,7 @@
4242
},
4343
"conflict": {
4444
"symfony/console": "<3.4",
45-
"symfony/form": "<4.1.2",
45+
"symfony/form": "<4.2",
4646
"symfony/translation": "<4.2"
4747
},
4848
"suggest": {

0 commit comments

Comments
 (0)