Skip to content

Commit

Permalink
bug #37279 [Form] Fixed prototype block prefixes hierarchy of the Col…
Browse files Browse the repository at this point in the history
…lectionType (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 #37024
| License       | MIT
| Doc PR        |

Following #37276

Commits
-------

65efc36 fixed prototype block prefixes hierarchy of the CollectionType
  • Loading branch information
fabpot committed Jun 15, 2020
2 parents ccd9c1f + 65efc36 commit 8bb0897
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
Expand Up @@ -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;
}

Expand Down
Expand Up @@ -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)
Expand Down

0 comments on commit 8bb0897

Please sign in to comment.