Skip to content

Commit 1d88387

Browse files
michaelKaefernicolas-grekas
authored andcommitted
[Form] Add prototype_options to CollectionType
1 parent c57c2eb commit 1d88387

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Add a `prototype_options` option to `CollectionType`
8+
49
6.0
510
---
611

Extension/Core/Type/CollectionType.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
3030
$prototypeOptions = array_replace([
3131
'required' => $options['required'],
3232
'label' => $options['prototype_name'].'label__',
33-
], $options['entry_options']);
33+
], array_replace($options['entry_options'], $options['prototype_options']));
3434

3535
if (null !== $options['prototype_data']) {
3636
$prototypeOptions['data'] = $options['prototype_data'];
@@ -120,12 +120,15 @@ public function configureOptions(OptionsResolver $resolver)
120120
'prototype_name' => '__name__',
121121
'entry_type' => TextType::class,
122122
'entry_options' => [],
123+
'prototype_options' => [],
123124
'delete_empty' => false,
124125
'invalid_message' => 'The collection is invalid.',
125126
]);
126127

127128
$resolver->setNormalizer('entry_options', $entryOptionsNormalizer);
129+
128130
$resolver->setAllowedTypes('delete_empty', ['bool', 'callable']);
131+
$resolver->setAllowedTypes('prototype_options', 'array');
129132
}
130133

131134
/**

Tests/Extension/Core/Type/CollectionTypeTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,23 @@ public function testPrototypeNotOverrideRequiredByEntryOptionsInFavorOfParent()
430430
$this->assertFalse($child->createView()->vars['prototype']->vars['required'], '"Prototype" should not be required');
431431
}
432432

433+
public function testPrototypeOptionsOverrideEntryOptions()
434+
{
435+
$form = $this->factory->create(static::TESTED_TYPE, [], [
436+
'allow_add' => true,
437+
'prototype' => true,
438+
'entry_type' => TextTypeTest::TESTED_TYPE,
439+
'entry_options' => [
440+
'help' => null,
441+
],
442+
'prototype_options' => [
443+
'help' => 'foo',
444+
],
445+
]);
446+
447+
$this->assertSame('foo', $form->createView()->vars['prototype']->vars['help']);
448+
}
449+
433450
public function testEntriesBlockPrefixes()
434451
{
435452
$collectionView = $this->factory->createNamed('fields', static::TESTED_TYPE, [''], [

0 commit comments

Comments
 (0)