-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Form] Add position support #11241
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
[Form] Add position support #11241
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,16 @@ | |
namespace Symfony\Component\Form; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\Form\Exception\InvalidArgumentException; | ||
use Symfony\Component\Form\Exception\BadMethodCallException; | ||
use Symfony\Component\Form\Exception\InvalidArgumentException; | ||
use Symfony\Component\Form\Exception\InvalidConfigurationException; | ||
|
||
/** | ||
* A builder for {@link Button} instances. | ||
* | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
*/ | ||
class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface | ||
class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface, OrderedFormConfigBuilderInterface | ||
{ | ||
/** | ||
* @var bool | ||
|
@@ -47,6 +48,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface | |
*/ | ||
private $attributes = array(); | ||
|
||
/** | ||
* @var null|string|array | ||
*/ | ||
private $position; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
|
@@ -503,6 +509,28 @@ public function setAutoInitialize($initialize) | |
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setPosition($position) | ||
{ | ||
if ($this->locked) { | ||
throw new BadMethodCallException('The config builder cannot be modified anymore.'); | ||
} | ||
|
||
if (is_string($position) && ($position !== 'first') && ($position !== 'last')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parenthesis can be removed here |
||
throw new InvalidConfigurationException('If you use position as string, you can only use "first" & "last".'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. first or last? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
if (is_array($position) && !isset($position['before']) && !isset($position['after'])) { | ||
throw new InvalidConfigurationException('If you use position as array, you must at least define the "before" or "after" option.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
$this->position = $position; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Unsupported method. | ||
* | ||
|
@@ -752,6 +780,14 @@ public function getAutoInitialize() | |
return false; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getPosition() | ||
{ | ||
return $this->position; | ||
} | ||
|
||
/** | ||
* Unsupported method. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config builder cannot be modified anymore as it is locked.
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, this is the button builder, not the form one.