8000 feature #29680 [Form] Add new block_prefix option for an easy form th… · symfony/form@b841ea8 · GitHub
[go: up one dir, main page]

Skip to content

Commit b841ea8

Browse 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 ------- bd50ac44fc Add block_prefix option for an easy form theming
2 parents c62262e + 2724868 commit b841ea8

File tree

7 files changed

+31
-5
< 8000 span class=" ml-2 fgColor-muted text-small" style="white-space:nowrap">lines changed

7 files changed

+31
-5
lines changed

CHANGELOG.md

Lines 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

Extension/Core/Type/BaseType.php

Lines 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
}

Tests/Extension/Core/Type/FormTypeTest.php

Lines 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
}

Tests/Fixtures/Descriptor/resolved_form_type_1.json

Lines 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",

Tests/Fixtures/Descriptor/resolved_form_type_1.txt

Lines 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

Tests/Fixtures/Descriptor/resolved_form_type_2.json

Lines 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",

Tests/Fixtures/Descriptor/resolved_form_type_2.txt

Lines 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