Skip to content

[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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[Form] Add position support
  • Loading branch information
GeLoLabs committed Jan 17, 2017
commit d26d931ac5cf756ad555d15227f1b3c8af2c6a33
40 changes: 38 additions & 2 deletions src/Symfony/Component/Form/ButtonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,6 +48,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*/
private $attributes = array();

/**
* @var null|string|array
*/
private $position;

/**
* @var array
*/
Expand Down Expand Up @@ -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.');
Copy link
Member

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.?

Copy link
Member

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.

}

if (is_string($position) && ($position !== 'first') && ($position !== 'last')) {
Copy link
Member

Choose a reason for hiding this comment

The 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".');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first or last?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using position as a string, the only supported values are "first" and "last".

}

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.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using position as an array, the "before" or "after" option must be defined.

}

$this->position = $position;

return $this;
}

/**
* Unsupported method.
*
Expand Down Expand Up @@ -752,6 +780,14 @@ public function getAutoInitialize()
return false;
}

/**
* {@inheritdoc}
*/
public function getPosition()
{
return $this->position;
}

/**
* Unsupported method.
*
Expand Down
7 changes: 5 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/BaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ abstract class BaseType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->setDisabled($options['disabled']);
$builder->setAutoInitialize($options['auto_initialize']);
$builder
->setDisabled($options['disabled'])
->setAutoInitialize($options['auto_initialize'])
->setPosition($options['position']);
}

/**
Expand Down Expand Up @@ -117,6 +119,7 @@ public function configureOptions(OptionsResolver $resolver)
'attr' => array(),
'translation_domain' => null,
'auto_initialize' => true,
'position' => null,
));

$resolver->setAllowedTypes('attr', 'array');
Expand Down
38 changes: 37 additions & 1 deletion src/Symfony/Component/Form/FormConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Form\Exception\BadMethodCallException;
use Symfony\Component\Form\Exception\InvalidArgumentException;
use Symfony\Component\Form\Exception\InvalidConfigurationException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\PropertyAccess\PropertyPath;
use Symfony\Component\PropertyAccess\PropertyPathInterface;
Expand All @@ -25,7 +26,7 @@
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class FormConfigBuilder implements FormConfigBuilderInterface
class FormConfigBuilder implements FormConfigBuilderInterface, OrderedFormConfigBuilderInterface
{
/**
* Caches a globally unique {@link NativeRequestHandler} instance.
Expand Down Expand Up @@ -172,6 +173,11 @@ class FormConfigBuilder implements FormConfigBuilderInterface
*/
private $autoInitialize = false;

/**
* @var null|string|array
*/
private $position;

/**
* @var array
*/
Expand Down Expand Up @@ -513,6 +519,14 @@ public function getAutoInitialize()
return $this->autoInitialize;
}

/**
* {@inheritdoc}
*/
public function getPosition()
{
return $this->position;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -831,6 +845,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')) {
throw new InvalidConfigurationException('If you use position as string, you can only use "first" & "last".');
}

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.');
}

$this->position = $position;

return $this;
}

/**
* {@inheritdoc}
*/
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy