Skip to content

Commit c025ff2

Browse files
Merge branch '6.2' into 6.3
* 6.2: [FrameworkBundle] Fix registering ExpressionValidator Bump Symfony version to 6.2.9 Update VERSION for 6.2.8 Update CHANGELOG for 6.2.8 Bump Symfony version to 5.4.23 Update VERSION for 5.4.22 Update CONTRIBUTORS for 5.4.22 Update CHANGELOG for 5.4.22 [Form] CollectionType apply prototypeOptions to ResizeFormListener new fields [FrameworkBundle] Fix services usages output for text descriptor
2 parents 1909c4a + 751efa8 commit c025ff2

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

Extension/Core/EventListener/ResizeFormListener.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,20 @@ class ResizeFormListener implements EventSubscriberInterface
2626
{
2727
protected $type;
2828
protected $options;
29+
protected $prototypeOptions;
2930
protected $allowAdd;
3031
protected $allowDelete;
3132

3233
private \Closure|bool $deleteEmpty;
3334

34-
public function __construct(string $type, array $options = [], bool $allowAdd = false, bool $allowDelete = false, bool|callable $deleteEmpty = false)
35+
public function __construct(string $type, array $options = [], bool $allowAdd = false, bool $allowDelete = false, bool|callable $deleteEmpty = false, array $prototypeOptions = null)
3536
{
3637
$this->type = $type;
3738
$this->allowAdd = $allowAdd;
3839
$this->allowDelete = $allowDelete;
3940
$this->options = $options;
4041
$this->deleteEmpty = \is_bool($deleteEmpty) ? $deleteEmpty : $deleteEmpty(...);
42+
$this->prototypeOptions = $prototypeOptions ?? $options;
4143
}
4244

4345
public static function getSubscribedEvents(): array
@@ -102,7 +104,7 @@ public function preSubmit(FormEvent $event)
102104
if (!$form->has($name)) {
103105
$form->add($name, $this->type, array_replace([
104106
'property_path' => '['.$name.']',
105-
], $this->options));
107+
], $this->prototypeOptions));
106108
}
107109
}
108110
}

Extension/Core/Type/CollectionType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class CollectionType extends AbstractType
2626
*/
2727
public function buildForm(FormBuilderInterface $builder, array $options)
2828
{
29+
$prototypeOptions = null;
2930
if ($options['allow_add'] && $options['prototype']) {
3031
$prototypeOptions = array_replace([
3132
'required' => $options['required'],
@@ -45,7 +46,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
4546
$options['entry_options'],
4647
$options['allow_add'],
4748
$options['allow_delete'],
48-
$options['delete_empty']
49+
$options['delete_empty'],
50+
$prototypeOptions
4951
);
5052

5153
$builder->addEventSubscriber($resizeListener);

Tests/Extension/Core/Type/CollectionTypeTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,29 @@ public function testPrototypeOptionsOverrideEntryOptions()
443443
$this->assertSame('foo', $form->createView()->vars['prototype']->vars['help']);
444444
}
445445

446+
public function testPrototypeOptionsAppliedToNewFields()
447+
{
448+
$form = $this->factory->create(static::TESTED_TYPE, ['first'], [
449+
'allow_add' => true,
450+
'prototype' => true,
451+
'entry_type' => TextTypeTest::TESTED_TYPE,
452+
'entry_options' => [
453+
'disabled' => true,
454+
],
455+
'prototype_options' => [
456+
'disabled' => false,
457+
],
458+
]);
459+
460+
$form->submit(['first_changed', 'second']);
461+
462+
$this->assertTrue($form->has('0'));
463+
$this->assertTrue($form->has('1'));
464+
$this->assertSame('first', $form[0]->getData());
465+
$this->assertSame('second', $form[1]->getData());
466+
$this->assertSame(['first', 'second'], $form->getData());
467+
}
468+
446469
public function testEntriesBlockPrefixes()
447470
{
448471
$collectionView = $this->factory->createNamed('fields', static::TESTED_TYPE, [''], [

0 commit comments

Comments
 (0)