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

Appearance settings

Commit b948d5a

Browse filesBrowse files
committed
feature #29680 [Form] Add new block_prefix option for an easy form theming (yceruto)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Form] Add new block_prefix option for an easy form theming | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29651 | License | MIT | Doc PR | symfony/symfony-docs#10835 Commits ------- bd50ac4 Add block_prefix option for an easy form theming
2 parents 743b52f + bd50ac4 commit b948d5a
Copy full SHA for b948d5a

File tree

7 files changed

+31
-5
lines changed
Filter options

7 files changed

+31
-5
lines changed

‎src/Symfony/Component/Form/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* added `block_prefix` option to `BaseType`.
8+
49
4.2.0
510
-----
611

‎src/Symfony/Component/Form/Extension/Core/Type/BaseType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/BaseType.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)
7979
for ($type = $form->getConfig()->getType(); null !== $type; $type = $type->getParent()) {
8080
array_unshift($blockPrefixes, $type->getBlockPrefix());
8181
}
82+
if (null !== $options['block_prefix']) {
83+
$blockPrefixes[] = $options['block_prefix'];
84+
}
8285
$blockPrefixes[] = $uniqueBlockPrefix;
8386

8487
$view->vars = array_replace($view->vars, array(
@@ -111,6 +114,7 @@ public function configureOptions(OptionsResolver $resolver)
111114
{
112115
$resolver->setDefaults(array(
113116
'block_name' => null,
117+
'block_prefix' => null,
114118
'disabled' => false,
115119
'label' => null,
116120
'label_format' => null,
@@ -119,6 +123,7 @@ public function configureOptions(OptionsResolver $resolver)
119123
'auto_initialize' => true,
120124
));
121125

126+
$resolver->setAllowedTypes('block_prefix', array('null', 'string'));
122127
$resolver->setAllowedTypes('attr', 'array');
123128
}
124129
}

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,16 @@ public function testSubmitNull($expected = null, $norm = null, $view = null)
639639
{
640640
parent::testSubmitNull(array(), array(), array());
641641
}
642+
643+
public function testPassBlockPrefixToViewWithParent()
644+
{
645+
$view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE)
646+
->add('child', $this->getTestedType(), array(
647+
'block_prefix' => 'child',
648+
))
649+
->getForm()
650+
->createView();
651+
652+
$this->assertSame(array('form', 'child', '_parent_child'), $view['child']->vars['block_prefixes']);
653+
}
642654
}

‎src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"attr",
3333
"auto_initialize",
3434
"block_name",
35+
"block_prefix",
3536
"by_reference",
3637
"data",
3738
"disabled",

‎src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ Symfony\Component\Form\Extension\Core\Type\ChoiceType (Block prefix: "choice")
1212
choice_translation_domain empty_data attr csrf_protection
1313
choice_value error_bubbling auto_initialize csrf_token_id
1414
choices trim block_name csrf_token_manager
15-
expanded by_reference
16-
group_by data
17-
multiple disabled
18-
placeholder help
19-
preferred_choices help_attr
15+
expanded block_prefix
16+
group_by by_reference
17+
multiple data
18+
placeholder disabled
19+
preferred_choices help
20+
help_attr
2021
inherit_data
2122
label
2223
label_attr

‎src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"attr",
99
"auto_initialize",
1010
"block_name",
11+
"block_prefix",
1112
"by_reference",
1213
"compound",
1314
"data",

‎src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.txt
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Symfony\Component\Form\Extension\Core\Type\FormType (Block prefix: "form")
1010
attr
1111
auto_initialize
1212
block_name
13+
block_prefix
1314
by_reference
1415
compound
1516
data

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.