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 9f0c7bf

Browse filesBrowse files
committed
Fixed Button::setParent() when already submitted
1 parent e52d977 commit 9f0c7bf
Copy full SHA for 9f0c7bf

File tree

2 files changed

+22
-2
lines changed
Filter options

2 files changed

+22
-2
lines changed

‎src/Symfony/Component/Form/Button.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Button.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public function offsetUnset($offset)
106106
*/
107107
public function setParent(FormInterface $parent = null)
108108
{
109+
if ($this->submitted) {
110+
throw new AlreadySubmittedException('You cannot set the parent of a submitted button');
111+
}
112+
109113
$this->parent = $parent;
110114
}
111115

‎src/Symfony/Component/Form/Tests/ButtonTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/ButtonTest.php
+18-2Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,34 @@ protected function setUp()
3030
$this->factory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
3131
}
3232

33+
/**
34+
* @expectedException \Symfony\Component\Form\Exception\AlreadySubmittedException
35+
*/
36+
public function testSetParentOnSubmittedButton()
37+
{
38+
$button = $this->getButtonBuilder('button')
39+
->getForm()
40+
;
41+
42+
$button->submit('');
43+
44+
$button->setParent($this->getFormBuilder('form')->getForm());
45+
}
46+
3347
/**
3448
* @dataProvider getDisabledStates
3549
*/
3650
public function testDisabledIfParentIsDisabled($parentDisabled, $buttonDisabled, $result)
3751
{
3852
$form = $this->getFormBuilder('form')
3953
->setDisabled($parentDisabled)
40-
->getForm();
54+
->getForm()
55+
;
4156

4257
$button = $this->getButtonBuilder('button')
4358
->setDisabled($buttonDisabled)
44-
->getForm();
59+
->getForm()
60+
;
4561

4662
$button->setParent($form);
4763

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.