Skip to content

Commit 8bb0897

Browse files
committed
bug symfony#37279 [Form] Fixed prototype block prefixes hierarchy of the CollectionType (yceruto)
This PR was merged into the 5.1 branch. Discussion ---------- [Form] Fixed prototype block prefixes hierarchy of the CollectionType | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#37024 | License | MIT | Doc PR | Following symfony#37276 Commits ------- 65efc36 fixed prototype block prefixes hierarchy of the CollectionType
2 parents ccd9c1f + 65efc36 commit 8bb0897

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
9393
$view->vars['multipart'] = true;
9494
}
9595

96-
if ($prefixOffset > -2 && $prototype->getConfig()->getOption('block_prefix')) {
96+
if ($prefixOffset > -3 && $prototype->getConfig()->getOption('block_prefix')) {
9797
--$prefixOffset;
9898
}
9999

src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php

+35-6
Original file line numberDiff line numberDiff line change
@@ -428,37 +428,66 @@ public function testEntriesBlockPrefixes()
428428
public function testEntriesBlockPrefixesWithCustomBlockPrefix()
429429
{
430430
$collectionView = $this->factory->createNamed('fields', static::TESTED_TYPE, [''], [
431+
'allow_add' => true,
431432
'entry_options' => ['block_prefix' => 'field'],
432433
])
433434
->createView()
434435
;
435436

436-
$this->assertCount(1, $collectionView);
437-
$this->assertSame([
437+
$expectedBlockPrefixes = [
438438
'form',
439439
'collection_entry',
440440
'text',
441441
'field',
442442
'_fields_entry',
443-
], $collectionView[0]->vars['block_prefixes']);
443+
];
444+
445+
$this->assertCount(1, $collectionView);
446+
$this->assertSame($expectedBlockPrefixes, $collectionView[0]->vars['block_prefixes']);
447+
$this->assertSame($expectedBlockPrefixes, $collectionView->vars['prototype']->vars['block_prefixes']);
444448
}
445449

446450
public function testEntriesBlockPrefixesWithCustomBlockPrefixedType()
447451
{
448452
$collectionView = $this->factory->createNamed('fields', static::TESTED_TYPE, [''], [
453+
'allow_add' => true,
449454
'entry_type' => BlockPrefixedFooTextType::class,
450455
])
451456
->createView()
452457
;
453458

454-
$this->assertCount(1, $collectionView);
455-
$this->assertSame([
459+
$expectedBlockPrefixes = [
456460
'form',
457461
'collection_entry',
458462
'block_prefixed_foo_text',
459463
'foo',
460464
'_fields_entry',
461-
], $collectionView[0]->vars['block_prefixes']);
465+
];
466+
467+
$this->assertCount(1, $collectionView);
468+
$this->assertSame($expectedBlockPrefixes, $collectionView[0]->vars['block_prefixes']);
469+
$this->assertSame($expectedBlockPrefixes, $collectionView->vars['prototype']->vars['block_prefixes']);
470+
}
471+
472+
public function testPrototypeBlockPrefixesWithCustomBlockPrefix()
473+
{
474+
$collectionView = $this->factory->createNamed('fields', static::TESTED_TYPE, [], [
475+
'allow_add' => true,
476+
'entry_options' => ['block_prefix' => 'field'],
477+
])
478+
->createView()
479+
;
480+
481+
$expectedBlockPrefixes = [
482+
'form',
483+
'collection_entry',
484+
'text',
485+
'field',
486+
'_fields_entry',
487+
];
488+
489+
$this->assertCount(0, $collectionView);
490+
$this->assertSame($expectedBlockPrefixes, $collectionView->vars['prototype']->vars['block_prefixes']);
462491
}
463492

464493
public function testSubmitNull($expected = null, $norm = null, $view = null)

0 commit comments

Comments
 (0)