[Form] Choice children can be template customized like collection
This commit is contained in:
parent
42f4b6db7b
commit
4e6b27fe90
@ -6,11 +6,20 @@
|
|||||||
{% endspaceless %}
|
{% endspaceless %}
|
||||||
{% endblock _text_id_widget %}
|
{% endblock _text_id_widget %}
|
||||||
|
|
||||||
{% block _name_entry_label %}
|
{% block _names_entry_label %}
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
{% if label is empty %}
|
{% if label is empty %}
|
||||||
{% set label = name|humanize %}
|
{% set label = name|humanize %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<label>Custom label: {{ label|trans({}, translation_domain) }}</label>
|
<label>Custom label: {{ label|trans({}, translation_domain) }}</label>
|
||||||
{% endspaceless %}
|
{% endspaceless %}
|
||||||
{% endblock _name_entry_label %}
|
{% endblock _names_entry_label %}
|
||||||
|
|
||||||
|
{% block _name_c_entry_label %}
|
||||||
|
{% spaceless %}
|
||||||
|
{% if label is empty %}
|
||||||
|
{% set label = name|humanize %}
|
||||||
|
{% endif %}
|
||||||
|
<label>Custom name label: {{ label|trans({}, translation_domain) }}</label>
|
||||||
|
{% endspaceless %}
|
||||||
|
{% endblock _name_c_entry_label %}
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
<?php if (!$label) { $label = $view['form']->humanize($name); } ?>
|
||||||
|
<label>Custom name label: <?php echo $view->escape($view['translator']->trans($label, array(), $translation_domain)) ?></label>
|
@ -256,6 +256,7 @@ class ChoiceType extends AbstractType
|
|||||||
'value' => $choiceView->value,
|
'value' => $choiceView->value,
|
||||||
'label' => $choiceView->label,
|
'label' => $choiceView->label,
|
||||||
'translation_domain' => $options['translation_domain'],
|
'translation_domain' => $options['translation_domain'],
|
||||||
|
'block_name' => 'entry',
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($options['multiple']) {
|
if ($options['multiple']) {
|
||||||
|
@ -283,7 +283,7 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
|
|||||||
|
|
||||||
public function testCollection()
|
public function testCollection()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createNamed('name', 'collection', array('a', 'b'), array(
|
$form = $this->factory->createNamed('names', 'collection', array('a', 'b'), array(
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -305,7 +305,7 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
|
|||||||
array('title' => 'a'),
|
array('title' => 'a'),
|
||||||
array('title' => 'b'),
|
array('title' => 'b'),
|
||||||
);
|
);
|
||||||
$form = $this->factory->createNamed('name', 'collection', $data, array(
|
$form = $this->factory->createNamed('names', 'collection', $data, array(
|
||||||
'type' => new AlternatingRowType(),
|
'type' => new AlternatingRowType(),
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -323,13 +323,13 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
|
|||||||
|
|
||||||
public function testEmptyCollection()
|
public function testEmptyCollection()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createNamed('name', 'collection', array(), array(
|
$form = $this->factory->createNamed('names', 'collection', array(), array(
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||||
'/div
|
'/div
|
||||||
[./input[@type="hidden"][@id="name__token"]]
|
[./input[@type="hidden"][@id="names__token"]]
|
||||||
[count(./div)=0]
|
[count(./div)=0]
|
||||||
'
|
'
|
||||||
);
|
);
|
||||||
@ -670,7 +670,7 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
|
|||||||
public function testCollectionRowWithCustomBlock()
|
public function testCollectionRowWithCustomBlock()
|
||||||
{
|
{
|
||||||
$collection = array('one', 'two', 'three');
|
$collection = array('one', 'two', 'three');
|
||||||
$form = $this->factory->createNamedBuilder('name', 'collection', $collection)
|
$form = $this->factory->createNamedBuilder('names', 'collection', $collection)
|
||||||
->getForm();
|
->getForm();
|
||||||
|
|
||||||
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||||
@ -684,6 +684,28 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The block "_name_c_entry_label" should be overridden in the theme of the
|
||||||
|
* implemented driver.
|
||||||
|
*/
|
||||||
|
public function testChoiceRowWithCustomBlock()
|
||||||
|
{
|
||||||
|
$form = $this->factory->createNamedBuilder('name_c', 'choice', 'a', array(
|
||||||
|
'choices' => array('a' => 'ChoiceA', 'b' => 'ChoiceB'),
|
||||||
|
'expanded' => true,
|
||||||
|
))
|
||||||
|
->getForm();
|
||||||
|
|
||||||
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||||
|
'/div
|
||||||
|
[
|
||||||
|
./label[.="Custom name label: [trans]ChoiceA[/trans]"]
|
||||||
|
/following-sibling::label[.="Custom name label: [trans]ChoiceB[/trans]"]
|
||||||
|
]
|
||||||
|
'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testFormEndWithRest()
|
public function testFormEndWithRest()
|
||||||
{
|
{
|
||||||
$view = $this->factory->createNamedBuilder('name', 'form')
|
$view = $this->factory->createNamedBuilder('name', 'form')
|
||||||
|
@ -193,7 +193,7 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
|
|||||||
|
|
||||||
public function testCollection()
|
public function testCollection()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createNamed('name', 'collection', array('a', 'b'), array(
|
$form = $this->factory->createNamed('names', 'collection', array('a', 'b'), array(
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
|
|||||||
[
|
[
|
||||||
./tr[./td/input[@type="text"][@value="a"]]
|
./tr[./td/input[@type="text"][@value="a"]]
|
||||||
/following-sibling::tr[./td/input[@type="text"][@value="b"]]
|
/following-sibling::tr[./td/input[@type="text"][@value="b"]]
|
||||||
/following-sibling::tr[@style="display: none"][./td[@colspan="2"]/input[@type="hidden"][@id="name__token"]]
|
/following-sibling::tr[@style="display: none"][./td[@colspan="2"]/input[@type="hidden"][@id="names__token"]]
|
||||||
]
|
]
|
||||||
[count(./tr[./td/input])=3]
|
[count(./tr[./td/input])=3]
|
||||||
'
|
'
|
||||||
@ -211,13 +211,13 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
|
|||||||
|
|
||||||
public function testEmptyCollection()
|
public function testEmptyCollection()
|
||||||
{
|
{
|
||||||
$form = $this->factory->createNamed('name', 'collection', array(), array(
|
$form = $this->factory->createNamed('names', 'collection', array(), array(
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||||
'/table
|
'/table
|
||||||
[./tr[@style="display: none"][./td[@colspan="2"]/input[@type="hidden"][@id="name__token"]]]
|
[./tr[@style="display: none"][./td[@colspan="2"]/input[@type="hidden"][@id="names__token"]]]
|
||||||
[count(./tr[./td/input])=1]
|
[count(./tr[./td/input])=1]
|
||||||
'
|
'
|
||||||
);
|
);
|
||||||
@ -439,7 +439,7 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
|
|||||||
public function testCollectionRowWithCustomBlock()
|
public function testCollectionRowWithCustomBlock()
|
||||||
{
|
{
|
||||||
$collection = array('one', 'two', 'three');
|
$collection = array('one', 'two', 'three');
|
||||||
$form = $this->factory->createNamedBuilder('name', 'collection', $collection)
|
$form = $this->factory->createNamedBuilder('names', 'collection', $collection)
|
||||||
->getForm();
|
->getForm();
|
||||||
|
|
||||||
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
$this->assertWidgetMatchesXpath($form->createView(), array(),
|
||||||
|
Reference in New Issue
Block a user