Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function configureOptions(OptionsResolver $resolver)
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,16 @@ public function testOverrideErrorBubbling()
$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, [
Expand Down Expand Up @@ -729,6 +739,28 @@ public function testPreferOwnHelpTranslationParameters()

$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
Expand Down