disable error bubbling by default when inherit_data is configured

This commit is contained in:
Christian Flothmann 2020-12-31 15:24:31 +01:00
parent 841ec99831
commit 8679c2ac05
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