Skip to content

Commit 9216816

Browse files
committed
[Form] Turned Twig filters into tests
1 parent 310f985 commit 9216816

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

src/Symfony/Bridge/Twig/Extension/FormExtension.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,16 @@ public function getFilters()
8080
{
8181
return array(
8282
'humanize' => new \Twig_Filter_Method($this, 'renderer->humanize'),
83-
'is_choice_group' => new \Twig_Filter_Function('is_array', array('is_safe' => array('html'))),
84-
'is_choice_selected' => new \Twig_Filter_Method($this, 'isChoiceSelected'),
83+
);
84+
}
85+
86+
/**
87+
* {@inheritdoc}
88+
*/
89+
public function getTests()
90+
{
91+
return array(
92+
'selectedchoice' => new \Twig_Test_Method($this, 'isSelectedChoice'),
8593
);
8694
}
8795

@@ -108,7 +116,7 @@ public function getFilters()
108116
*
109117
* @see ChoiceView::isSelected()
110118
*/
111-
public function isChoiceSelected(ChoiceView $choice, $selectedValue)
119+
public function isSelectedChoice(ChoiceView $choice, $selectedValue)
112120
{
113121
if (is_array($selectedValue)) {
114122
return false !== array_search($choice->value, $selectedValue, true);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@
8787
{% block choice_widget_options %}
8888
{% spaceless %}
8989
{% for group_label, choice in options %}
90-
{% if choice|is_choice_group %}
90+
{% if choice is iterable %}
9191
<optgroup label="{{ group_label|trans({}, translation_domain) }}">
9292
{% set options = choice %}
9393
{{ block('choice_widget_options') }}
9494
</optgroup>
9595
{% else %}
96-
<option value="{{ choice.value }}"{% if choice|is_choice_selected(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
96+
<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
9797
{% endif %}
9898
{% endfor %}
9999
{% endspaceless %}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function testThemeBlockInheritanceUsingExtend()
106106
);
107107
}
108108

109-
public function isChoiceSelectedProvider()
109+
public function isSelectedChoiceProvider()
110110
{
111111
// The commented cases should not be necessary anymore, because the
112112
// choice lists should assure that both values passed here are always
@@ -130,13 +130,13 @@ public function isChoiceSelectedProvider()
130130
}
131131

132132
/**
133-
* @dataProvider isChoiceSelectedProvider
133+
* @dataProvider isSelectedChoiceProvider
134134
*/
135135
public function testIsChoiceSelected($expected, $choice, $value)
136136
{
137137
$choice = new ChoiceView($choice, $choice . ' label');
138138

139-
$this->assertSame($expected, $this->extension->isChoiceSelected($choice, $value));
139+
$this->assertSame($expected, $this->extension->isSelectedChoice($choice, $value));
140140
}
141141

142142
protected function renderEnctype(FormView $view)

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ public function getName()
4949
return 'form';
5050
}
5151

52-
public function isChoiceSelected(ChoiceView $choice, $selectedValue)
53-
{
54-
return $this->renderer->isChoiceSelected($choice, $selectedValue);
55-
}
56-
5752
/**
5853
* Sets a theme for a given view.
5954
*

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,9 @@ CHANGELOG
113113
* deprecated the methods `getDefaultOptions` and `getAllowedOptionValues`
114114
in FormTypeInterface and FormTypeExtensionInterface
115115
* options passed during construction can now be accessed from FormConfigInterface
116-
* added FormBuilderInterface, FormView and FormConfigEditorInterface
117-
* [BC BREAK] the methods in FormTypeInterface and FormTypeExtensionInterface now
118-
receive FormBuilderInterface and FormView instead of FormBuilder and
119-
FormView
116+
* added FormBuilderInterface and FormConfigEditorInterface
117+
* [BC BREAK] the method `buildForm` in FormTypeInterface and FormTypeExtensionInterface
118+
now receives a FormBuilderInterface instead of a FormBuilder instance
120119
* [BC BREAK] the method `buildViewBottomUp` was renamed to `finishView` in
121120
FormTypeInterface and FormTypeExtensionInterface
122121
* [BC BREAK] the options array is now passed as last argument of the

0 commit comments

Comments
 (0)