Skip to content

Commit

Permalink
feature #13407 [Form] Remove deprecated setDefaultOptions and Options…
Browse files Browse the repository at this point in the history
…ResolverInterface (peterrehm)

This PR was merged into the 3.0-dev branch.

Discussion
----------

[Form] Remove deprecated setDefaultOptions and OptionsResolverInterface

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | symfony/symfony-docs#4786
| Related        | #12891

Commits
-------

9b9158b Remove the deprecated OptionsResolverInterface
6026781 Removed deprecated setDefaultOptions methods
  • Loading branch information
fabpot committed Feb 5, 2015
2 parents d68cb61 + d536e3e commit b7888da
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 58 deletions.
11 changes: 0 additions & 11 deletions AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Form;

use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
Expand Down Expand Up @@ -43,16 +42,6 @@ public function finishView(FormView $view, FormInterface $form, array $options)
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}

/**
* Configures the options for this type.
*
* @param OptionsResolver $resolver The resolver for the options.
*/
public function configureOptions(OptionsResolver $resolver)
{
}
Expand Down
11 changes: 0 additions & 11 deletions AbstractTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Form;

use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
Expand Down Expand Up @@ -43,16 +42,6 @@ public function finishView(FormView $view, FormInterface $form, array $options)
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}

/**
* Configures the options for this type.
*
* @param OptionsResolver $resolver The resolver for the options.
*/
public function configureOptions(OptionsResolver $resolver)
{
}
Expand Down
11 changes: 4 additions & 7 deletions FormTypeExtensionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Form;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
Expand Down Expand Up @@ -60,15 +60,12 @@ public function buildView(FormView $view, FormInterface $form, array $options);
public function finishView(FormView $view, FormInterface $form, array $options);

/**
* Overrides the default options from the extended type.
* Configures the options for this type.
*
* @param OptionsResolverInterface $resolver The resolver for the options.
* @param OptionsResolver $resolver The resolver for the options.
*
* @deprecated Deprecated since Symfony 2.7, to be removed in Symfony 3.0.
* Use the method configureOptions instead. This method will be
* added to the FormTypeExtensionInterface with Symfony 3.0
*/
public function setDefaultOptions(OptionsResolverInterface $resolver);
public function configureOptions(OptionsResolver $resolver);

/**
* Returns the name of the type being extended.
Expand Down
12 changes: 4 additions & 8 deletions FormTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Form;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
Expand Down Expand Up @@ -69,15 +69,11 @@ public function buildView(FormView $view, FormInterface $form, array $options);
public function finishView(FormView $view, FormInterface $form, array $options);

/**
* Sets the default options for this type.
* Configures the options for this type.
*
* @param OptionsResolverInterface $resolver The resolver for the options.
*
* @deprecated Deprecated since Symfony 2.7, to be renamed in Symfony 3.0.
* Use the method configureOptions instead. This method will be
* added to the FormTypeInterface with Symfony 3.0.
* @param OptionsResolver $resolver The resolver for the options.
*/
public function setDefaultOptions(OptionsResolverInterface $resolver);
public function configureOptions(OptionsResolver $resolver);

/**
* Returns the name of the parent type.
Expand Down
20 changes: 3 additions & 17 deletions ResolvedFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
/**
* Returns the configured options resolver used for this type.
*
* @return \Symfony\Component\OptionsResolver\OptionsResolverInterface The options resolver.
* @return \Symfony\Component\OptionsResolver\OptionsResolver The options resolver.
*/
public function getOptionsResolver()
{
Expand All @@ -203,24 +203,10 @@ public function getOptionsResolver()
$this->optionsResolver = new OptionsResolver();
}

$this->innerType->setDefaultOptions($this->optionsResolver);

$reflector = new \ReflectionMethod($this->innerType, 'setDefaultOptions');
$isOverwritten = ($reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType');

if (true === $isOverwritten) {
trigger_error('The FormTypeInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeInterface with Symfony 3.0.', E_USER_DEPRECATED);
}
$this->innerType->configureOptions($this->optionsResolver);

foreach ($this->typeExtensions as $extension) {
$extension->setDefaultOptions($this->optionsResolver);

$reflector = new \ReflectionMethod($extension, 'setDefaultOptions');
$isOverwritten = ($reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension');

if (true === $isOverwritten) {
trigger_error('The FormTypeExtensionInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeExtensionInterface with Symfony 3.0.', E_USER_DEPRECATED);
}
$extension->configureOptions($this->optionsResolver);
}
}

Expand Down
4 changes: 2 additions & 2 deletions ResolvedFormTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Form;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* A wrapper for a form type and its extensions.
Expand Down Expand Up @@ -102,7 +102,7 @@ public function finishView(FormView $view, FormInterface $form, array $options);
/**
* Returns the configured options resolver used for this type.
*
* @return OptionsResolverInterface The options resolver.
* @return OptionsResolver The options resolver.
*/
public function getOptionsResolver();
}
4 changes: 2 additions & 2 deletions Tests/ResolvedFormTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testCreateBuilder()
{
$givenOptions = array('a' => 'a_custom', 'c' => 'c_custom');
$resolvedOptions = array('a' => 'a_custom', 'b' => 'b_default', 'c' => 'c_custom', 'd' => 'd_default');
$optionsResolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolverInterface');
$optionsResolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolver');

$this->resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType')
->setConstructorArgs(array($this->type, array($this->extension1, $this->extension2), $this->parentResolvedType))
Expand Down Expand Up @@ -127,7 +127,7 @@ public function testCreateBuilderWithDataClassOption()
{
$givenOptions = array('data_class' => 'Foo');
$resolvedOptions = array('data_class' => '\stdClass');
$optionsResolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolverInterface');
$optionsResolver = $this->getMock('Symfony\Component\OptionsResolver\OptionsResolver');

$this->resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType')
->setConstructorArgs(array($this->type, array($this->extension1, $this->extension2), $this->parentResolvedType))
Expand Down

0 comments on commit b7888da

Please sign in to comment.