Skip to content

Commit a1054ec

Browse files
tijsverkoyennicolas-grekas
authored andcommitted
[TwigBridge] Use a div instead of p to prevent invalid HTML
1 parent f6feeaa commit a1054ec

File tree

7 files changed

+35
-30
lines changed

7 files changed

+35
-30
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Wrap help messages on form elements in `div` instead of `p`
8+
49
5.4
510
---
611

Resources/views/Form/form_div_layout.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
{% block form_help -%}
326326
{%- if help is not empty -%}
327327
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' help-text')|trim}) -%}
328-
<p id="{{ id }}_help"{% with { attr: help_attr } %}{{ block('attributes') }}{% endwith %}>
328+
<div id="{{ id }}_help"{% with { attr: help_attr } %}{{ block('attributes') }}{% endwith %}>
329329
{%- if translation_domain is same as(false) -%}
330330
{%- if help_html is same as(false) -%}
331331
{{- help -}}
@@ -339,7 +339,7 @@
339339
{{- help|trans(help_translation_parameters, translation_domain)|raw -}}
340340
{%- endif -%}
341341
{%- endif -%}
342-
</p>
342+
</div>
343343
{%- endif -%}
344344
{%- endblock form_help %}
345345

Tests/Extension/AbstractBootstrap5HorizontalLayoutTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public function testCheckboxRowWithHelp()
245245
./div[@class="col-sm-2" or @class="col-sm-10"]
246246
/following-sibling::div[@class="col-sm-2" or @class="col-sm-10"]
247247
[
248-
./p
248+
./div
249249
[@class="form-text mb-0 help-text"]
250250
[.="[trans]really helpful text[/trans]"]
251251
]
@@ -266,7 +266,7 @@ public function testRadioRowWithHelp()
266266
./div[@class="col-sm-2" or @class="col-sm-10"]
267267
/following-sibling::div[@class="col-sm-2" or @class="col-sm-10"]
268268
[
269-
./p
269+
./div
270270
[@class="form-text mb-0 help-text"]
271271
[.="[trans]really helpful text[/trans]"]
272272
]

Tests/Extension/AbstractBootstrap5LayoutTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function testHelp()
198198
$html = $this->renderHelp($view);
199199

200200
$this->assertMatchesXpath($html,
201-
'/p
201+
'/div
202202
[@id="name_help"]
203203
[@class="form-text mb-0 help-text"]
204204
[.="[trans]Help text test![/trans]"]
@@ -218,7 +218,7 @@ public function testHelpAttr()
218218
$html = $this->renderHelp($view);
219219

220220
$this->assertMatchesXpath($html,
221-
'/p
221+
'/div
222222
[@id="name_help"]
223223
[@class="class-test form-text mb-0 help-text"]
224224
[.="[trans]Help text test![/trans]"]
@@ -236,15 +236,15 @@ public function testHelpHtmlDefaultIsFalse()
236236
$html = $this->renderHelp($view);
237237

238238
$this->assertMatchesXpath($html,
239-
'/p
239+
'/div
240240
[@id="name_help"]
241241
[@class="form-text mb-0 help-text"]
242242
[.="[trans]Help <b>text</b> test![/trans]"]
243243
'
244244
);
245245

246246
$this->assertMatchesXpath($html,
247-
'/p
247+
'/div
248248
[@id="name_help"]
249249
[@class="form-text mb-0 help-text"]
250250
/b
@@ -264,15 +264,15 @@ public function testHelpHtmlIsFalse()
264264
$html = $this->renderHelp($view);
265265

266266
$this->assertMatchesXpath($html,
267-
'/p
267+
'/div
268268
[@id="name_help"]
269269
[@class="form-text mb-0 help-text"]
270270
[.="[trans]Help <b>text</b> test![/trans]"]
271271
'
272272
);
273273

274274
$this->assertMatchesXpath($html,
275-
'/p
275+
'/div
276276
[@id="name_help"]
277277
[@class="form-text mb-0 help-text"]
278278
/b
@@ -290,15 +290,15 @@ public function testHelpHtmlIsTrue()
290290
$html = $this->renderHelp($form->createView());
291291

292292
$this->assertMatchesXpath($html,
293-
'/p
293+
'/div
294294
[@id="name_help"]
295295
[@class="form-text mb-0 help-text"]
296296
[.="[trans]Help <b>text</b> test![/trans]"]
297297
', 0
298298
);
299299

300300
$this->assertMatchesXpath($html,
301-
'/p
301+
'/div
302302
[@id="name_help"]
303303
[@class="form-text mb-0 help-text"]
304304
/b
@@ -377,7 +377,7 @@ public function testCheckboxRowWithHelp()
377377
[@for="name"]
378378
[.="[trans]foo[/trans]"]
379379
]
380-
/following-sibling::p
380+
/following-sibling::div
381381
[@class="form-text mb-0 help-text"]
382382
[.="[trans]really helpful text[/trans]"]
383383
]
@@ -871,7 +871,7 @@ public function testRadioRowWithHelp()
871871
'/div
872872
[@class="mb-3"]
873873
[
874-
./p
874+
./div
875875
[@class="form-text mb-0 help-text"]
876876
[.="[trans]really helpful text[/trans]"]
877877
]

Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function testHelpAttr()
203203
$html = $this->renderHelp($view);
204204

205205
$this->assertMatchesXpath($html,
206-
'/p
206+
'/div
207207
[@id="name_help"]
208208
[@class="class-test help-text"]
209209
[.="[trans]Help text test![/trans]"]
@@ -221,15 +221,15 @@ public function testHelpHtmlDefaultIsFalse()
221221
$html = $this->renderHelp($view);
222222

223223
$this->assertMatchesXpath($html,
224-
'/p
224+
'/div
225225
[@id="name_help"]
226226
[@class="help-text"]
227227
[.="[trans]Help <b>text</b> test![/trans]"]
228228
'
229229
);
230230

231231
$this->assertMatchesXpath($html,
232-
'/p
232+
'/div
233233
[@id="name_help"]
234234
[@class="help-text"]
235235
/b
@@ -249,15 +249,15 @@ public function testHelpHtmlIsFalse()
249249
$html = $this->renderHelp($view);
250250

251251
$this->assertMatchesXpath($html,
252-
'/p
252+
'/div
253253
[@id="name_help"]
254254
[@class="help-text"]
255255
[.="[trans]Help <b>text</b> test![/trans]"]
256256
'
257257
);
258258

259259
$this->assertMatchesXpath($html,
260-
'/p
260+
'/div
261261
[@id="name_help"]
262262
[@class="help-text"]
263263
/b
@@ -277,15 +277,15 @@ public function testHelpHtmlIsTrue()
277277
$html = $this->renderHelp($view);
278278

279279
$this->assertMatchesXpath($html,
280-
'/p
280+
'/div
281281
[@id="name_help"]
282282
[@class="help-text"]
283283
[.="[trans]Help <b>text</b> test![/trans]"]
284284
', 0
285285
);
286286

287287
$this->assertMatchesXpath($html,
288-
'/p
288+
'/div
289289
[@id="name_help"]
290290
[@class="help-text"]
291291
/b

Tests/Extension/FormExtensionTableLayoutTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function testHelpAttr()
8989
$html = $this->renderHelp($view);
9090

9191
$this->assertMatchesXpath($html,
92-
'/p
92+
'/div
9393
[@id="name_help"]
9494
[@class="class-test help-text"]
9595
[.="[trans]Help text test![/trans]"]
@@ -107,15 +107,15 @@ public function testHelpHtmlDefaultIsFalse()
107107
$html = $this->renderHelp($view);
108108

109109
$this->assertMatchesXpath($html,
110-
'/p
110+
'/div
111111
[@id="name_help"]
112112
[@class="help-text"]
113113
[.="[trans]Help <b>text</b> test![/trans]"]
114114
'
115115
);
116116

117117
$this->assertMatchesXpath($html,
118-
'/p
118+
'/div
119119
[@id="name_help"]
120120
[@class="help-text"]
121121
/b
@@ -135,15 +135,15 @@ public function testHelpHtmlIsFalse()
135135
$html = $this->renderHelp($view);
136136

137137
$this->assertMatchesXpath($html,
138-
'/p
138+
'/div
139139
[@id="name_help"]
140140
[@class="help-text"]
141141
[.="[trans]Help <b>text</b> test![/trans]"]
142142
'
143143
);
144144

145145
$this->assertMatchesXpath($html,
146-
'/p
146+
'/div
147147
[@id="name_help"]
148148
[@class="help-text"]
149149
/b
@@ -163,15 +163,15 @@ public function testHelpHtmlIsTrue()
163163
$html = $this->renderHelp($view);
164164

165165
$this->assertMatchesXpath($html,
166-
'/p
166+
'/div
167167
[@id="name_help"]
168168
[@class="help-text"]
169169
[.="[trans]Help <b>text</b> test![/trans]"]
170170
', 0
171171
);
172172

173173
$this->assertMatchesXpath($html,
174-
'/p
174+
'/div
175175
[@id="name_help"]
176176
[@class="help-text"]
177177
/b

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"symfony/asset": "^5.4|^6.0",
2828
"symfony/dependency-injection": "^5.4|^6.0",
2929
"symfony/finder": "^5.4|^6.0",
30-
"symfony/form": "^5.4|^6.0",
30+
"symfony/form": "^6.1",
3131
"symfony/http-foundation": "^5.4|^6.0",
3232
"symfony/http-kernel": "^5.4|^6.0",
3333
"symfony/intl": "^5.4|^6.0",
@@ -55,7 +55,7 @@
5555
"phpdocumentor/reflection-docblock": "<3.2.2",
5656
"phpdocumentor/type-resolver": "<1.4.0",
5757
"symfony/console": "<5.4",
58-
"symfony/form": "<5.4",
58+
"symfony/form": "<6.1",
5959
"symfony/http-foundation": "<5.4",
6060
"symfony/http-kernel": "<5.4",
6161
"symfony/translation": "<5.4",

0 commit comments

Comments
 (0)