Fix choice translation domain for expanded choice widget
This commit is contained in:
parent
b6dbfa4b73
commit
52755ba26d
@ -98,6 +98,7 @@
|
||||
{%- for child in form %}
|
||||
{{- form_widget(child, {
|
||||
parent_label_class: label_attr.class|default(''),
|
||||
translation_domain: choice_translation_domain,
|
||||
}) -}}
|
||||
{% endfor -%}
|
||||
</div>
|
||||
@ -106,6 +107,7 @@
|
||||
{%- for child in form %}
|
||||
{{- form_widget(child, {
|
||||
parent_label_class: label_attr.class|default(''),
|
||||
translation_domain: choice_translation_domain,
|
||||
}) -}}
|
||||
{% endfor -%}
|
||||
</div>
|
||||
@ -169,7 +171,7 @@
|
||||
{% endif %}
|
||||
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
|
||||
{{- widget|raw -}}
|
||||
{{- label is not sameas(false) ? label|trans({}, translation_domain) -}}
|
||||
{{- label is not sameas(false) ? (translation_domain is sameas(false) ? label : label|trans({}, translation_domain)) -}}
|
||||
</label>
|
||||
{% endif %}
|
||||
{% endblock checkbox_radio_label %}
|
||||
|
@ -46,7 +46,7 @@
|
||||
<div {{ block('widget_container_attributes') }}>
|
||||
{%- for child in form %}
|
||||
{{- form_widget(child) -}}
|
||||
{{- form_label(child) -}}
|
||||
{{- form_label(child, null, {translation_domain: choice_translation_domain}) -}}
|
||||
{% endfor -%}
|
||||
</div>
|
||||
{%- endblock choice_widget_expanded -%}
|
||||
@ -220,7 +220,7 @@
|
||||
{% set label = name|humanize %}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
|
||||
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ translation_domain is sameas(false) ? label : label|trans({}, translation_domain) }}</label>
|
||||
{%- endif -%}
|
||||
{%- endblock form_label -%}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<div <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
|
||||
<?php foreach ($form as $child): ?>
|
||||
<?php echo $view['form']->widget($child) ?>
|
||||
<?php echo $view['form']->label($child) ?>
|
||||
<?php echo $view['form']->label($child, null, array('translation_domain' => $choice_translation_domain)) ?>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
|
@ -4,5 +4,5 @@
|
||||
<?php if (!$label) { $label = isset($label_format)
|
||||
? strtr($label_format, array('%name%' => $name, '%id%' => $id))
|
||||
: $view['form']->humanize($name); } ?>
|
||||
<label <?php foreach ($label_attr as $k => $v) { printf('%s="%s" ', $view->escape($k), $view->escape($v)); } ?>><?php echo $view->escape($view['translator']->trans($label, array(), $translation_domain)) ?></label>
|
||||
<label <?php foreach ($label_attr as $k => $v) { printf('%s="%s" ', $view->escape($k), $view->escape($v)); } ?>><?php echo $view->escape(false !== $translation_domain ? $view['translator']->trans($label, array(), $translation_domain) : $label) ?></label>
|
||||
<?php endif ?>
|
||||
|
@ -231,6 +231,29 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testSingleChoiceWithoutTranslation()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choice_translation_domain' => false,
|
||||
));
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')),
|
||||
'/select
|
||||
[@name="name"]
|
||||
[@class="my&class form-control"]
|
||||
[not(@required)]
|
||||
[
|
||||
./option[@value="&a"][@selected="selected"][.="Choice&A"]
|
||||
/following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"]
|
||||
]
|
||||
[count(./option)=2]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSingleChoiceAttributes()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||
@ -629,6 +652,42 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testSingleChoiceExpandedWithoutTranslation()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'choice_translation_domain' => false,
|
||||
));
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||
'/div
|
||||
[
|
||||
./div
|
||||
[@class="radio"]
|
||||
[
|
||||
./label
|
||||
[.="Choice&A"]
|
||||
[
|
||||
./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
|
||||
]
|
||||
]
|
||||
/following-sibling::div
|
||||
[@class="radio"]
|
||||
[
|
||||
./label
|
||||
[.="Choice&B"]
|
||||
[
|
||||
./input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
|
||||
]
|
||||
]
|
||||
/following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
|
||||
]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSingleChoiceExpandedAttributes()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||
@ -792,6 +851,52 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testMultipleChoiceExpandedWithoutTranslation()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', array('&a', '&c'), array(
|
||||
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B', '&c' => 'Choice&C'),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choice_translation_domain' => false,
|
||||
));
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||
'/div
|
||||
[
|
||||
./div
|
||||
[@class="checkbox"]
|
||||
[
|
||||
./label
|
||||
[.="Choice&A"]
|
||||
[
|
||||
./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
|
||||
]
|
||||
]
|
||||
/following-sibling::div
|
||||
[@class="checkbox"]
|
||||
[
|
||||
./label
|
||||
[.="Choice&B"]
|
||||
[
|
||||
./input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)]
|
||||
]
|
||||
]
|
||||
/following-sibling::div
|
||||
[@class="checkbox"]
|
||||
[
|
||||
./label
|
||||
[.="Choice&C"]
|
||||
[
|
||||
./input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)]
|
||||
]
|
||||
]
|
||||
/following-sibling::input[@type="hidden"][@id="name__token"][@class="form-control"]
|
||||
]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMultipleChoiceExpandedAttributes()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', array('&a', '&c'), array(
|
||||
|
@ -168,6 +168,20 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
);
|
||||
}
|
||||
|
||||
public function testLabelWithoutTranslation()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'text', null, array(
|
||||
'translation_domain' => false,
|
||||
));
|
||||
|
||||
$this->assertMatchesXpath($this->renderLabel($form->createView()),
|
||||
'/label
|
||||
[@for="name"]
|
||||
[.="Name"]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testLabelOnForm()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'date');
|
||||
@ -513,6 +527,28 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
);
|
||||
}
|
||||
|
||||
public function testSingleChoiceWithoutTranslation()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choice_translation_domain' => false,
|
||||
));
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||
'/select
|
||||
[@name="name"]
|
||||
[not(@required)]
|
||||
[
|
||||
./option[@value="&a"][@selected="selected"][.="Choice&A"]
|
||||
/following-sibling::option[@value="&b"][not(@selected)][.="Choice&B"]
|
||||
]
|
||||
[count(./option)=2]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSingleChoiceAttributes()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||
@ -889,6 +925,29 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
);
|
||||
}
|
||||
|
||||
public function testSingleChoiceExpandedWithoutTranslation()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B'),
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'choice_translation_domain' => false,
|
||||
));
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||
'/div
|
||||
[
|
||||
./input[@type="radio"][@name="name"][@id="name_0"][@value="&a"][@checked]
|
||||
/following-sibling::label[@for="name_0"][.="Choice&A"]
|
||||
/following-sibling::input[@type="radio"][@name="name"][@id="name_1"][@value="&b"][not(@checked)]
|
||||
/following-sibling::label[@for="name_1"][.="Choice&B"]
|
||||
/following-sibling::input[@type="hidden"][@id="name__token"]
|
||||
]
|
||||
[count(./input)=3]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSingleChoiceExpandedAttributes()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', '&a', array(
|
||||
@ -986,6 +1045,32 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
);
|
||||
}
|
||||
|
||||
public function testMultipleChoiceExpandedWithoutTranslation()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', array('&a', '&c'), array(
|
||||
'choices' => array('&a' => 'Choice&A', '&b' => 'Choice&B', '&c' => 'Choice&C'),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choice_translation_domain' => false,
|
||||
));
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||
'/div
|
||||
[
|
||||
./input[@type="checkbox"][@name="name[]"][@id="name_0"][@checked][not(@required)]
|
||||
/following-sibling::label[@for="name_0"][.="Choice&A"]
|
||||
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_1"][not(@checked)][not(@required)]
|
||||
/following-sibling::label[@for="name_1"][.="Choice&B"]
|
||||
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_2"][@checked][not(@required)]
|
||||
/following-sibling::label[@for="name_2"][.="Choice&C"]
|
||||
/following-sibling::input[@type="hidden"][@id="name__token"]
|
||||
]
|
||||
[count(./input)=4]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMultipleChoiceExpandedAttributes()
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'choice', array('&a', '&c'), array(
|
||||
|
Reference in New Issue
Block a user