8000 [Form] Choice children can be template customized like collection by adrienbrault · Pull Request #9033 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Choice children can be template customized like collection #9033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Symfony/Bridge/Twig/Tests/Extension/custom_widgets.html.twig
8000
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@
{% endspaceless %}
{% endblock _text_id_widget %}

{% block _name_entry_label %}
{% block _names_entry_label %}
{% spaceless %}
{% if label is empty %}
{% set label = name|humanize %}
{% endif %}
<label>Custom label: {{ label|trans({}, translation_domain) }}</label>
{% 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 %}
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ private function addSubForms(FormBuilderInterface $builder, array $choiceViews,
'value' => $choiceView->value,
'label' => $choiceView->label,
'translation_domain' => $options['translation_domain'],
'block_name' => 'entry',
);

if ($options['multiple']) {
Expand Down
32 changes: 27 additions & 5 deletions src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function testRestAndRepeatedWithWidgetPerChild()

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',
));

Expand All @@ -305,7 +305,7 @@ public function testCollectionWithAlternatingRowTypes()
array('title' => 'a'),
array('title' => 'b'),
);
$form = $this->factory->createNamed('name', 'collection', $data, array(
$form = $this->factory->createNamed('names', 'collection', $data, array(
'type' => new AlternatingRowType(),
));

Expand All @@ -323,13 +323,13 @@ public function testCollectionWithAlternatingRowTypes()

public function testEmptyCollection()
{
$form = $this->factory->createNamed('name', 'collection', array(), array(
$form = $this->factory->createNamed('names', 'collection', array(), array(
'type' => 'text',
));

$this->assertWidgetMatchesXpath($form->createView(), array(),
'/div
[./input[@type="hidden"][@id="name__token"]]
[./input[@type="hidden"][@id="names__token"]]
[count(./div)=0]
'
);
Expand Down Expand Up @@ -670,7 +670,7 @@ public function testThemeInheritance($parentTheme, $childTheme)
public function testCollectionRowWithCustomBlock()
{
$collection = array('one', 'two', 'three');
$form = $this->factory->createNamedBuilder('name', 'collection', $collection)
$form = $this->factory->createNamedBuilder('names', 'collection', $collection)
->getForm();

$this->assertWidgetMatchesXpath($form->createView(), array(),
Expand All @@ -684,6 +684,28 @@ public function testCollectionRowWithCustomBlock()
);
}

/**
* 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()
{
$view = $this->factory->createNamedBuilder('name', 'form')
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function testRest()

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',
));

Expand All @@ -202,7 +202,7 @@ public function testCollection()
[
./tr[./td/input[@type="text"][@value="a"]]
/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]
'
Expand All @@ -211,13 +211,13 @@ public function testCollection()

public function testEmptyCollection()
{
$form = $this->factory->createNamed('name', 'collection', array(), array(
$form = $this->factory->createNamed('names', 'collection', array(), array(
'type' => 'text',
));

$this->assertWidgetMatchesXpath($form->createView(), array(),
'/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]
'
);
Expand Down Expand Up @@ -439,7 +439,7 @@ public function testRepeatedWithCustomOptions()
public function testCollectionRowWithCustomBlock()
{
$collection = array('one', 'two', 'three');
$form = $this->factory->createNamedBuilder('name', 'collection', $collection)
$form = $this->factory->createNamedBuilder('names', 'collection', $collection)
->getForm();

$this->assertWidgetMatchesXpath($form->createView(), array(),
Expand Down
0