Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Form] Fixed prototype block prefixes hierarchy of the CollectionType #37279

Merged
merged 1 commit into from Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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