bug #39670 [Form] disable error bubbling by default when inherit_data is configured (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Form] disable error bubbling by default when inherit_data is configured

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #14441
| License       | MIT
| Doc PR        |

Commits
-------

8679c2ac05 disable error bubbling by default when inherit_data is configured
This commit is contained in:
Fabien Potencier 2021-01-03 09:24:31 +01:00
commit da07550827
2 changed files with 33 additions and 1 deletions

View File

@ -157,7 +157,7 @@ class FormType extends BaseType
// For any form that is not represented by a single HTML control,
// errors should bubble up by default
$errorBubbling = function (Options $options) {
return $options['compound'];
return $options['compound'] && !$options['inherit_data'];
};
// If data is given, the form is locked to that data

View File

@ -512,6 +512,16 @@ class FormTypeTest extends BaseTypeTest
$this->assertTrue($form->getConfig()->getErrorBubbling());
}
public function testErrorBubblingForCompoundFieldsIsDisabledByDefaultIfInheritDataIsEnabled()
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
'compound' => true,
'inherit_data' => true,
]);
$this->assertFalse($form->getConfig()->getErrorBubbling());
}
public function testPropertyPath()
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
@ -729,6 +739,28 @@ class FormTypeTest extends BaseTypeTest
$this->assertEquals(['%parent_param%' => 'parent_value', '%override_param%' => 'child_value'], $view['child']->vars['help_translation_parameters']);
}
public function testErrorBubblingDoesNotSkipCompoundFieldsWithInheritDataConfigured()
{
$form = $this->factory->createNamedBuilder('form', self::TESTED_TYPE)
->add(
$this->factory->createNamedBuilder('inherit_data_type', self::TESTED_TYPE, null, [
'inherit_data' => true,
])
->add('child', self::TESTED_TYPE, [
'compound' => false,
'error_bubbling' => true,
])
)
->getForm();
$error = new FormError('error message');
$form->get('inherit_data_type')->get('child')->addError($error);
$this->assertCount(0, $form->getErrors());
$this->assertCount(1, $form->get('inherit_data_type')->getErrors());
$this->assertSame($error, $form->get('inherit_data_type')->getErrors()[0]);
$this->assertCount(0, $form->get('inherit_data_type')->get('child')->getErrors());
}
}
class Money