Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit239fe04

Browse files
przemyslaw-bogusznicolas-grekas
authored andcommitted
[Form] Add label_html attribute
1 parent421c7f8 commit239fe04

15 files changed

+288
-8
lines changed

‎src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
{%-endif -%}
100100
{%-endif -%}
101101
<label{%with {attr:label_attr } %}{{block('attributes') }}{%endwith %}>
102-
{{-widget|raw }} {{labelis notsame as(false)? (translation_domainissame as(false)?label:label|trans(label_translation_parameters,translation_domain)) -}}
102+
{{-widget|raw }} {{labelis notsame as(false)? (translation_domainissame as(false)?(label_htmlissame as(false)?label:label|raw): (label_htmlissame as(false)?label|trans(label_translation_parameters,translation_domain):label|trans(label_translation_parameters,translation_domain)|raw)) -}}
103103
</label>
104104
{%-endif -%}
105105
{%-endblockcheckbox_radio_label %}

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,21 @@
231231
{%setlabel=name|humanize %}
232232
{%-endif -%}
233233
{%-endif -%}
234-
<{{element|default('label') }}{%iflabel_attr %}{%with {attr:label_attr } %}{{block('attributes') }}{%endwith %}{%endif %}>{{translation_domainissame as(false)?label:label|trans(label_translation_parameters,translation_domain) }}{%blockform_label_errors %}{{- form_errors(form) -}}{%endblockform_label_errors %}</{{element|default('label') }}>
234+
<{{element|default('label') }}{%iflabel_attr %}{%with {attr:label_attr } %}{{block('attributes') }}{%endwith %}{%endif %}>
235+
{%-iftranslation_domainissame as(false) -%}
236+
{%-iflabel_htmlissame as(false) -%}
237+
{{-label -}}
238+
{%-else -%}
239+
{{-label|raw -}}
240+
{%-endif -%}
241+
{%-else -%}
242+
{%-iflabel_htmlissame as(false) -%}
243+
{{-label|trans(label_translation_parameters,translation_domain) -}}
244+
{%-else -%}
245+
{{-label|trans(label_translation_parameters,translation_domain)|raw -}}
246+
{%-endif -%}
247+
{%-endif -%}
248+
{%blockform_label_errors %}{{- form_errors(form) -}}{%endblockform_label_errors %}</{{element|default('label') }}>
235249
{%-else -%}
236250
{%-iferrors|length>0 -%}
237251
<divid="{{id }}_errors"class="mb-2">
@@ -273,7 +287,21 @@
273287

274288
{{widget|raw }}
275289
<label{%with {attr:label_attr } %}{{block('attributes') }}{%endwith %}>
276-
{{-labelis notsame as(false)? (translation_domainissame as(false)?label:label|trans(label_translation_parameters,translation_domain)) -}}
290+
{%-iflabelis notsame as(false) -%}
291+
{%-iftranslation_domainissame as(false) -%}
292+
{%-iflabel_htmlissame as(false) -%}
293+
{{-label -}}
294+
{%-else -%}
295+
{{-label|raw -}}
296+
{%-endif -%}
297+
{%-else -%}
298+
{%-iflabel_htmlissame as(false) -%}
299+
{{-label|trans(label_translation_parameters,translation_domain) -}}
300+
{%-else -%}
301+
{{-label|trans(label_translation_parameters,translation_domain)|raw -}}
302+
{%-endif -%}
303+
{%-endif -%}
304+
{%-endif -%}
277305
{{- form_errors(form) -}}
278306
</label>
279307
{%-endif -%}

‎src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,21 @@
232232
{%setlabel=name|humanize %}
233233
{%-endif -%}
234234
{%-endif -%}
235-
<buttontype="{{type|default('button') }}" {{block('button_attributes') }}>{{translation_domainissame as(false)orlabelissame as(false)?label:label|trans(label_translation_parameters,translation_domain) }}</button>
235+
<buttontype="{{type|default('button') }}" {{block('button_attributes') }}>
236+
{%-iftranslation_domainissame as(false) -%}
237+
{%-iflabel_htmlissame as(false) -%}
238+
{{-label -}}
239+
{%-else -%}
240+
{{-label|raw -}}
241+
{%-endif -%}
242+
{%-else -%}
243+
{%-iflabel_htmlissame as(false) -%}
244+
{{-label|trans(label_translation_parameters,translation_domain) -}}
245+
{%-else -%}
246+
{{-label|trans(label_translation_parameters,translation_domain)|raw -}}
247+
{%-endif -%}
248+
{%-endif -%}
249+
</button>
236250
{%-endblockbutton_widget -%}
237251

238252
{%-blocksubmit_widget -%}
@@ -288,9 +302,17 @@
288302
{%-endif -%}
289303
<{{element|default('label') }}{%iflabel_attr %}{%with {attr:label_attr } %}{{block('attributes') }}{%endwith %}{%endif %}>
290304
{%-iftranslation_domainissame as(false) -%}
291-
{{-label -}}
305+
{%-iflabel_htmlissame as(false) -%}
306+
{{-label -}}
307+
{%-else -%}
308+
{{-label|raw -}}
309+
{%-endif -%}
292310
{%-else -%}
293-
{{-label|trans(label_translation_parameters,translation_domain) -}}
311+
{%-iflabel_htmlissame as(false) -%}
312+
{{-label|trans(label_translation_parameters,translation_domain) -}}
313+
{%-else -%}
314+
{{-label|trans(label_translation_parameters,translation_domain)|raw -}}
315+
{%-endif -%}
294316
{%-endif -%}
295317
</{{element|default('label') }}>
296318
{%-endif -%}

‎src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3HorizontalLayoutTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,39 @@ public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly
100100
);
101101
}
102102

103+
publicfunctiontestLabelHtmlDefaultIsFalse()
104+
{
105+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
106+
'label' =>'<b>Bolded label</b>',
107+
]);
108+
109+
$html =$this->renderLabel($form->createView(),null, [
110+
'label_attr' => [
111+
'class' =>'my&class',
112+
],
113+
]);
114+
115+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class col-sm-2 control-label required"][.="[trans]<b>Bolded label</b>[/trans]"]');
116+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class col-sm-2 control-label required"]/b[.="Bolded label"]',0);
117+
}
118+
119+
publicfunctiontestLabelHtmlIsTrue()
120+
{
121+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
122+
'label' =>'<b>Bolded label</b>',
123+
'label_html' =>true,
124+
]);
125+
126+
$html =$this->renderLabel($form->createView(),null, [
127+
'label_attr' => [
128+
'class' =>'my&class',
129+
],
130+
]);
131+
132+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class col-sm-2 control-label required"][.="[trans]<b>Bolded label</b>[/trans]"]',0);
133+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class col-sm-2 control-label required"]/b[.="Bolded label"]');
134+
}
135+
103136
publicfunctiontestStartTag()
104137
{
105138
$form =$this->factory->create('Symfony\Component\Form\Extension\Core\Type\FormType',null, [

‎src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,39 @@ public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly
106106
);
107107
}
108108

109+
publicfunctiontestLabelHtmlDefaultIsFalse()
110+
{
111+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
112+
'label' =>'<b>Bolded label</b>',
113+
]);
114+
115+
$html =$this->renderLabel($form->createView(),null, [
116+
'label_attr' => [
117+
'class' =>'my&class',
118+
],
119+
]);
120+
121+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class control-label required"][.="[trans]<b>Bolded label</b>[/trans]"]');
122+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class control-label required"]/b[.="Bolded label"]',0);
123+
}
124+
125+
publicfunctiontestLabelHtmlIsTrue()
126+
{
127+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
128+
'label' =>'<b>Bolded label</b>',
129+
'label_html' =>true,
130+
]);
131+
132+
$html =$this->renderLabel($form->createView(),null, [
133+
'label_attr' => [
134+
'class' =>'my&class',
135+
],
136+
]);
137+
138+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class control-label required"][.="[trans]<b>Bolded label</b>[/trans]"]',0);
139+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class control-label required"]/b[.="Bolded label"]');
140+
}
141+
109142
publicfunctiontestHelp()
110143
{
111144
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
@@ -2663,6 +2696,31 @@ public function testButtonlabelWithoutTranslation()
26632696
);
26642697
}
26652698

2699+
publicfunctiontestButtonLabelHtmlDefaultIsFalse()
2700+
{
2701+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\ButtonType',null, [
2702+
'label' =>'<b>Click here!</b>',
2703+
]);
2704+
2705+
$html =$this->renderWidget($form->createView(), ['attr' => ['class' =>'my&class']]);
2706+
2707+
$this->assertMatchesXpath($html,'/button[@type="button"][@name="name"][.="[trans]<b>Click here!</b>[/trans]"][@class="my&class btn"]');
2708+
$this->assertMatchesXpath($html,'/button[@type="button"][@name="name"][@class="my&class btn"]/b[.="Click here!"]',0);
2709+
}
2710+
2711+
publicfunctiontestButtonLabelHtmlIsTrue()
2712+
{
2713+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\ButtonType',null, [
2714+
'label' =>'<b>Click here!</b>',
2715+
'label_html' =>true,
2716+
]);
2717+
2718+
$html =$this->renderWidget($form->createView(), ['attr' => ['class' =>'my&class']]);
2719+
2720+
$this->assertMatchesXpath($html,'/button[@type="button"][@name="name"][.="[trans]<b>Click here!</b>[/trans]"][@class="my&class btn"]',0);
2721+
$this->assertMatchesXpath($html,'/button[@type="button"][@name="name"][@class="my&class btn"]/b[.="Click here!"]');
2722+
}
2723+
26662724
publicfunctiontestSubmit()
26672725
{
26682726
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\SubmitType');

‎src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4HorizontalLayoutTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,39 @@ public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly
132132
);
133133
}
134134

135+
publicfunctiontestLabelHtmlDefaultIsFalse()
136+
{
137+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
138+
'label' =>'<b>Bolded label</b>',
139+
]);
140+
141+
$html =$this->renderLabel($form->createView(),null, [
142+
'label_attr' => [
143+
'class' =>'my&class',
144+
],
145+
]);
146+
147+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class col-form-label col-sm-2 required"][.="[trans]<b>Bolded label</b>[/trans]"]');
148+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class col-form-label col-sm-2 required"]/b[.="Bolded label"]',0);
149+
}
150+
151+
publicfunctiontestLabelHtmlIsTrue()
152+
{
153+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
154+
'label' =>'<b>Bolded label</b>',
155+
'label_html' =>true,
156+
]);
157+
158+
$html =$this->renderLabel($form->createView(),null, [
159+
'label_attr' => [
160+
'class' =>'my&class',
161+
],
162+
]);
163+
164+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class col-form-label col-sm-2 required"][.="[trans]<b>Bolded label</b>[/trans]"]',0);
165+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class col-form-label col-sm-2 required"]/b[.="Bolded label"]');
166+
}
167+
135168
publicfunctiontestLegendOnExpandedType()
136169
{
137170
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\ChoiceType',null, [

‎src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4LayoutTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,39 @@ public function testLabelWithCustomTextAsOptionAndCustomAttributesPassedDirectly
141141
);
142142
}
143143

144+
publicfunctiontestLabelHtmlDefaultIsFalse()
145+
{
146+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
147+
'label' =>'<b>Bolded label</b>',
148+
]);
149+
150+
$html =$this->renderLabel($form->createView(),null, [
151+
'label_attr' => [
152+
'class' =>'my&class',
153+
],
154+
]);
155+
156+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class required"][.="[trans]<b>Bolded label</b>[/trans]"]');
157+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class required"]/b[.="Bolded label"]',0);
158+
}
159+
160+
publicfunctiontestLabelHtmlIsTrue()
161+
{
162+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
163+
'label' =>'<b>Bolded label</b>',
164+
'label_html' =>true,
165+
]);
166+
167+
$html =$this->renderLabel($form->createView(),null, [
168+
'label_attr' => [
169+
'class' =>'my&class',
170+
],
171+
]);
172+
173+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class required"][.="[trans]<b>Bolded label</b>[/trans]"]',0);
174+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class required"]/b[.="Bolded label"]');
175+
}
176+
144177
publicfunctiontestLegendOnExpandedType()
145178
{
146179
$form =$this->factory->createNamed('name', ChoiceType::class,null, [

‎src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,39 @@ public function testHelpHtmlIsTrue()
295295
);
296296
}
297297

298+
publicfunctiontestLabelHtmlDefaultIsFalse()
299+
{
300+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
301+
'label' =>'<b>Bolded label</b>',
302+
]);
303+
304+
$html =$this->renderLabel($form->createView(),null, [
305+
'label_attr' => [
306+
'class' =>'my&class',
307+
],
308+
]);
309+
310+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class required"][.="[trans]<b>Bolded label</b>[/trans]"]');
311+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class required"]/b[.="Bolded label"]',0);
312+
}
313+
314+
publicfunctiontestLabelHtmlIsTrue()
315+
{
316+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
317+
'label' =>'<b>Bolded label</b>',
318+
'label_html' =>true,
319+
]);
320+
321+
$html =$this->renderLabel($form->createView(),null, [
322+
'label_attr' => [
323+
'class' =>'my&class',
324+
],
325+
]);
326+
327+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class required"][.="[trans]<b>Bolded label</b>[/trans]"]',0);
328+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class required"]/b[.="Bolded label"]');
329+
}
330+
298331
protectedfunctionrenderForm(FormView$view,array$vars = [])
299332
{
300333
return (string)$this->renderer->renderBlock($view,'form',$vars);

‎src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionTableLayoutTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,39 @@ public function testHelpHtmlIsTrue()
181181
);
182182
}
183183

184+
publicfunctiontestLabelHtmlDefaultIsFalse()
185+
{
186+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
187+
'label' =>'<b>Bolded label</b>',
188+
]);
189+
190+
$html =$this->renderLabel($form->createView(),null, [
191+
'label_attr' => [
192+
'class' =>'my&class',
193+
],
194+
]);
195+
196+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class required"][.="[trans]<b>Bolded label</b>[/trans]"]');
197+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class required"]/b[.="Bolded label"]',0);
198+
}
199+
200+
publicfunctiontestLabelHtmlIsTrue()
201+
{
202+
$form =$this->factory->createNamed('name','Symfony\Component\Form\Extension\Core\Type\TextType',null, [
203+
'label' =>'<b>Bolded label</b>',
204+
'label_html' =>true,
205+
]);
206+
207+
$html =$this->renderLabel($form->createView(),null, [
208+
'label_attr' => [
209+
'class' =>'my&class',
210+
],
211+
]);
212+
213+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class required"][.="[trans]<b>Bolded label</b>[/trans]"]',0);
214+
$this->assertMatchesXpath($html,'/label[@for="name"][@class="my&class required"]/b[.="Bolded label"]');
215+
}
216+
184217
protectedfunctionrenderForm(FormView$view,array$vars = [])
185218
{
186219
return (string)$this->renderer->renderBlock($view,'form',$vars);

‎src/Symfony/Bridge/Twig/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"symfony/asset":"^4.4|^5.0",
2626
"symfony/dependency-injection":"^4.4|^5.0",
2727
"symfony/finder":"^4.4|^5.0",
28-
"symfony/form":"^5.0",
28+
"symfony/form":"^5.1",
2929
"symfony/http-foundation":"^4.4|^5.0",
3030
"symfony/http-kernel":"^4.4|^5.0",
3131
"symfony/mime":"^4.4|^5.0",
@@ -48,7 +48,7 @@
4848
},
4949
"conflict": {
5050
"symfony/console":"<4.4",
51-
"symfony/form":"<5.0",
51+
"symfony/form":"<5.1",
5252
"symfony/http-foundation":"<4.4",
5353
"symfony/http-kernel":"<4.4",
5454
"symfony/translation":"<5.0",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp