bug #36411 [Form] RepeatedType should always have inner types mapped (biozshock)
This PR was merged into the 3.4 branch.
Discussion
----------
[Form] RepeatedType should always have inner types mapped
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Doc PR| https://github.com/symfony/symfony-docs/pull/13519 |
| Tickets | Fix #36410
| License | MIT
Always set mapped=true to override inner type mapped setting.
Throw an exception if inner types of RepeatedType has mapped=false
Commits
-------
728cd66a13
RepeatedType should always have inner types mapped
This commit is contained in:
commit
f70286333f
@ -31,13 +31,16 @@ class RepeatedType extends AbstractType
|
|||||||
$options['options']['error_bubbling'] = $options['error_bubbling'];
|
$options['options']['error_bubbling'] = $options['error_bubbling'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// children fields must always be mapped
|
||||||
|
$defaultOptions = ['mapped' => true];
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->addViewTransformer(new ValueToDuplicatesTransformer([
|
->addViewTransformer(new ValueToDuplicatesTransformer([
|
||||||
$options['first_name'],
|
$options['first_name'],
|
||||||
$options['second_name'],
|
$options['second_name'],
|
||||||
]))
|
]))
|
||||||
->add($options['first_name'], $options['type'], array_merge($options['options'], $options['first_options']))
|
->add($options['first_name'], $options['type'], array_merge($options['options'], $options['first_options'], $defaultOptions))
|
||||||
->add($options['second_name'], $options['type'], array_merge($options['options'], $options['second_options']))
|
->add($options['second_name'], $options['type'], array_merge($options['options'], $options['second_options'], $defaultOptions))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\Form;
|
use Symfony\Component\Form\Form;
|
||||||
|
use Symfony\Component\Form\Tests\Fixtures\NotMappedType;
|
||||||
|
|
||||||
class RepeatedTypeTest extends BaseTypeTest
|
class RepeatedTypeTest extends BaseTypeTest
|
||||||
{
|
{
|
||||||
@ -78,6 +79,41 @@ class RepeatedTypeTest extends BaseTypeTest
|
|||||||
$this->assertFalse($form['second']->isRequired());
|
$this->assertFalse($form['second']->isRequired());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMappedOverridesDefault()
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(NotMappedType::class);
|
||||||
|
$this->assertFalse($form->getConfig()->getMapped());
|
||||||
|
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
|
'type' => NotMappedType::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertTrue($form['first']->getConfig()->getMapped());
|
||||||
|
$this->assertTrue($form['second']->getConfig()->getMapped());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider notMappedConfigurationKeys
|
||||||
|
*/
|
||||||
|
public function testNotMappedInnerIsOverridden($configurationKey)
|
||||||
|
{
|
||||||
|
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||||
|
'type' => TextTypeTest::TESTED_TYPE,
|
||||||
|
$configurationKey => ['mapped' => false],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertTrue($form['first']->getConfig()->getMapped());
|
||||||
|
$this->assertTrue($form['second']->getConfig()->getMapped());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function notMappedConfigurationKeys()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['first_options'],
|
||||||
|
['second_options'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function testSetInvalidOptions()
|
public function testSetInvalidOptions()
|
||||||
{
|
{
|
||||||
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
|
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
|
||||||
|
23
src/Symfony/Component/Form/Tests/Fixtures/NotMappedType.php
Normal file
23
src/Symfony/Component/Form/Tests/Fixtures/NotMappedType.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Form\Tests\Fixtures;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class NotMappedType extends AbstractType
|
||||||
|
{
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
$resolver->setDefault('mapped', false);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user