Skip to content

Commit fd4882a

Browse files
committed
disable error bubbling by default when inherit_data is configured
1 parent 696228a commit fd4882a

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Extension/Core/Type/FormType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function configureOptions(OptionsResolver $resolver)
157157
// For any form that is not represented by a single HTML control,
158158
// errors should bubble up by default
159159
$errorBubbling = function (Options $options) {
160-
return $options['compound'];
160+
return $options['compound'] && !$options['inherit_data'];
161161
};
162162

163163
// If data is given, the form is locked to that data

Tests/Extension/Core/Type/FormTypeTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,16 @@ public function testOverrideErrorBubbling()
512512
$this->assertTrue($form->getConfig()->getErrorBubbling());
513513
}
514514

515+
public function testErrorBubblingForCompoundFieldsIsDisabledByDefaultIfInheritDataIsEnabled()
516+
{
517+
$form = $this->factory->create(static::TESTED_TYPE, null, [
518+
'compound' => true,
519+
'inherit_data' => true,
520+
]);
521+
522+
$this->assertFalse($form->getConfig()->getErrorBubbling());
523+
}
524+
515525
public function testPropertyPath()
516526
{
517527
$form = $this->factory->create(static::TESTED_TYPE, null, [
@@ -729,6 +739,28 @@ public function testPreferOwnHelpTranslationParameters()
729739

730740
$this->assertEquals(['%parent_param%' => 'parent_value', '%override_param%' => 'child_value'], $view['child']->vars['help_translation_parameters']);
731741
}
742+
743+
public function testErrorBubblingDoesNotSkipCompoundFieldsWithInheritDataConfigured()
744+
{
745+
$form = $this->factory->createNamedBuilder('form', self::TESTED_TYPE)
746+
->add(
747+
$this->factory->createNamedBuilder('inherit_data_type', self::TESTED_TYPE, null, [
748+
'inherit_data' => true,
749+
])
750+
->add('child', self::TESTED_TYPE, [
751+
'compound' => false,
752+
'error_bubbling' => true,
753+
])
754+
)
755+
->getForm();
756+
$error = new FormError('error message');
757+
$form->get('inherit_data_type')->get('child')->addError($error);
758+
759+
$this->assertCount(0, $form->getErrors());
760+
$this->assertCount(1, $form->get('inherit_data_type')->getErrors());
761+
$this->assertSame($error, $form->get('inherit_data_type')->getErrors()[0]);
762+
$this->assertCount(0, $form->get('inherit_data_type')->get('child')->getErrors());
763+
}
732764
}
733765

734766
class Money

0 commit comments

Comments
 (0)