diff --git a/src/Symfony/Component/Form/AbstractRendererEngine.php b/src/Symfony/Component/Form/AbstractRendererEngine.php index 8202cbf97b641..f0fa5fbe80359 100644 --- a/src/Symfony/Component/Form/AbstractRendererEngine.php +++ b/src/Symfony/Component/Form/AbstractRendererEngine.php @@ -171,7 +171,7 @@ private function loadResourceForBlockNameHierarchy($cacheKey, FormView $view, ar // The next two if statements contain slightly duplicated code. This is by intention // and tries to avoid execution of unnecessary checks in order to increase performance. - if (isset($this->resources[$cacheKey][$parentBlockName])) { + if (isset($this->resources[$cacheKey][$parentBlockName]) && $this->resources[$cacheKey][$parentBlockName] !== false) { // It may happen that the parent block is already loaded, but its level is not. // In this case, the parent block must have been loaded by loadResourceForBlock(), // which does not check the hierarchy of the block. Subsequently the block must have diff --git a/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php b/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php index d68337e3bc8c1..80089efd933b6 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/BaseType.php @@ -77,7 +77,10 @@ public function buildView(FormView $view, FormInterface $form, array $options) $blockPrefixes = array(); for ($type = $form->getConfig()->getType(); null !== $type; $type = $type->getParent()) { - array_unshift($blockPrefixes, $type->getBlockPrefix()); + $blockPrefix = $type->getBlockPrefix(); + if (!in_array($blockPrefix, $blockPrefixes)) { + array_unshift($blockPrefixes, $blockPrefix); + } } $blockPrefixes[] = $uniqueBlockPrefix; diff --git a/src/Symfony/Component/Form/Tests/FixtureTypeTest.php b/src/Symfony/Component/Form/Tests/FixtureTypeTest.php new file mode 100644 index 0000000000000..b8ec8c97a362f --- /dev/null +++ b/src/Symfony/Component/Form/Tests/FixtureTypeTest.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests; + +class FixtureTypeTest extends \Symfony\Component\Form\Test\TypeTestCase +{ + /** + * @dataProvider provideTypeClassBlockPrefix + */ + public function testUniqueBlockPrefixes($typeClass, $blockPrefixes) + { + $form = $this->factory->create($typeClass); + $view = $form->createView(); + $this->assertEquals($view->vars['block_prefixes'], $blockPrefixes); + } + + /** + * @return array + */ + public function provideTypeClassBlockPrefix() + { + return array( + array(__NAMESPACE__.'\Fixtures\Foo', ['form','foo','_foo']), + array(__NAMESPACE__.'\Fixtures\Type', ['form', 'type', '_type']), + array(__NAMESPACE__.'\Fixtures\FooBarHTMLType',['form', 'foo_bar_html', '_foo_bar_html']), + array(__NAMESPACE__.'\Fixtures\Foo1Bar2Type', ['form', 'foo1_bar2', '_foo1_bar2']), + array(__NAMESPACE__.'\Fixtures\OtherType\Foo1Bar2Type', ['form', 'foo1_bar2', '_foo1_bar2']), + array(__NAMESPACE__.'\Fixtures\FBooType', ['form', 'f_boo', '_f_boo']), + ); + } +} diff --git a/src/Symfony/Component/Form/Tests/Fixtures/OtherType/Foo1Bar2Type.php b/src/Symfony/Component/Form/Tests/Fixtures/OtherType/Foo1Bar2Type.php new file mode 100644 index 0000000000000..f6717ae2e4d3b --- /dev/null +++ b/src/Symfony/Component/Form/Tests/Fixtures/OtherType/Foo1Bar2Type.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Fixtures\OtherType; + +use Symfony\Component\Form\AbstractType; + +class Foo1Bar2Type extends AbstractType +{ + public function getParent() + { + return 'Symfony\Component\Form\Tests\Fixtures\Foo1Bar2Type'; + } +}