diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php index ea6a6d5ffec1..758ef08bb9ee 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php @@ -93,7 +93,7 @@ public function finishView(FormView $view, FormInterface $form, array $options) $view->vars['multipart'] = true; } - if ($prefixOffset > -2 && $prototype->getConfig()->getOption('block_prefix')) { + if ($prefixOffset > -3 && $prototype->getConfig()->getOption('block_prefix')) { --$prefixOffset; } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php index 3d2ac4fe9c62..706c3f850629 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php @@ -428,37 +428,66 @@ public function testEntriesBlockPrefixes() public function testEntriesBlockPrefixesWithCustomBlockPrefix() { $collectionView = $this->factory->createNamed('fields', static::TESTED_TYPE, [''], [ + 'allow_add' => true, 'entry_options' => ['block_prefix' => 'field'], ]) ->createView() ; - $this->assertCount(1, $collectionView); - $this->assertSame([ + $expectedBlockPrefixes = [ 'form', 'collection_entry', 'text', 'field', '_fields_entry', - ], $collectionView[0]->vars['block_prefixes']); + ]; + + $this->assertCount(1, $collectionView); + $this->assertSame($expectedBlockPrefixes, $collectionView[0]->vars['block_prefixes']); + $this->assertSame($expectedBlockPrefixes, $collectionView->vars['prototype']->vars['block_prefixes']); } public function testEntriesBlockPrefixesWithCustomBlockPrefixedType() { $collectionView = $this->factory->createNamed('fields', static::TESTED_TYPE, [''], [ + 'allow_add' => true, 'entry_type' => BlockPrefixedFooTextType::class, ]) ->createView() ; - $this->assertCount(1, $collectionView); - $this->assertSame([ + $expectedBlockPrefixes = [ 'form', 'collection_entry', 'block_prefixed_foo_text', 'foo', '_fields_entry', - ], $collectionView[0]->vars['block_prefixes']); + ]; + + $this->assertCount(1, $collectionView); + $this->assertSame($expectedBlockPrefixes, $collectionView[0]->vars['block_prefixes']); + $this->assertSame($expectedBlockPrefixes, $collectionView->vars['prototype']->vars['block_prefixes']); + } + + public function testPrototypeBlockPrefixesWithCustomBlockPrefix() + { + $collectionView = $this->factory->createNamed('fields', static::TESTED_TYPE, [], [ + 'allow_add' => true, + 'entry_options' => ['block_prefix' => 'field'], + ]) + ->createView() + ; + + $expectedBlockPrefixes = [ + 'form', + 'collection_entry', + 'text', + 'field', + '_fields_entry', + ]; + + $this->assertCount(0, $collectionView); + $this->assertSame($expectedBlockPrefixes, $collectionView->vars['prototype']->vars['block_prefixes']); } public function testSubmitNull($expected = null, $norm = null, $view = null)