Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit da07550

Browse filesBrowse files
committed
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 ------- 8679c2a disable error bubbling by default when inherit_data is configured
2 parents 4bced61 + 8679c2a commit da07550
Copy full SHA for da07550

File tree

2 files changed

+33
-1
lines changed
Filter options

2 files changed

+33
-1
lines changed

‎src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/FormType.php
+1-1Lines 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

‎src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php
+32Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.