diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index f1cbf0ba4f875..45e085d488671 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.3.0 +----- + + * added `block_prefix` option to `BaseType`. + 4.2.0 ----- diff --git a/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php b/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php index d68337e3bc8c1..91c6d8615c7cc 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php @@ -79,6 +79,9 @@ public function buildView(FormView $view, FormInterface $form, array $options) for ($type = $form->getConfig()->getType(); null !== $type; $type = $type->getParent()) { array_unshift($blockPrefixes, $type->getBlockPrefix()); } + if (null !== $options['block_prefix']) { + $blockPrefixes[] = $options['block_prefix']; + } $blockPrefixes[] = $uniqueBlockPrefix; $view->vars = array_replace($view->vars, array( @@ -111,6 +114,7 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'block_name' => null, + 'block_prefix' => null, 'disabled' => false, 'label' => null, 'label_format' => null, @@ -119,6 +123,7 @@ public function configureOptions(OptionsResolver $resolver) 'auto_initialize' => true, )); + $resolver->setAllowedTypes('block_prefix', array('null', 'string')); $resolver->setAllowedTypes('attr', 'array'); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index 68f30ef16bc05..2f08dd6ad4830 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -639,4 +639,16 @@ public function testSubmitNull($expected = null, $norm = null, $view = null) { parent::testSubmitNull(array(), array(), array()); } + + public function testPassBlockPrefixToViewWithParent() + { + $view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE) + ->add('child', $this->getTestedType(), array( + 'block_prefix' => 'child', + )) + ->getForm() + ->createView(); + + $this->assertSame(array('form', 'child', '_parent_child'), $view['child']->vars['block_prefixes']); + } } diff --git a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json index eb7f21af962e4..e274979eb8815 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json +++ b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json @@ -32,6 +32,7 @@ "attr", "auto_initialize", "block_name", + "block_prefix", "by_reference", "data", "disabled", diff --git a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt index 500a6e0dd2b2f..7de8dce90e385 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt +++ b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt @@ -12,11 +12,12 @@ Symfony\Component\Form\Extension\Core\Type\ChoiceType (Block prefix: "choice") choice_translation_domain empty_data attr csrf_protection choice_value error_bubbling auto_initialize csrf_token_id choices trim block_name csrf_token_manager - expanded by_reference - group_by data - multiple disabled - placeholder help - preferred_choices help_attr + expanded block_prefix + group_by by_reference + multiple data + placeholder disabled + preferred_choices help + help_attr inherit_data label label_attr diff --git a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.json b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.json index eb93423adf651..e36dadf31fefb 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.json +++ b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.json @@ -8,6 +8,7 @@ "attr", "auto_initialize", "block_name", + "block_prefix", "by_reference", "compound", "data", diff --git a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.txt b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.txt index 5b97c854c7b06..560d9c25d78c2 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.txt +++ b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_2.txt @@ -10,6 +10,7 @@ Symfony\Component\Form\Extension\Core\Type\FormType (Block prefix: "form") attr auto_initialize block_name + block_prefix by_reference compound data pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy