Skip to content

[Form] deprecate the unused scale option #28570

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
Sep 24, 2018
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
2 changes: 2 additions & 0 deletions UPGRADE-4.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Finder
Form
----

* The `scale` option of the `IntegerType` is deprecated.

* Deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered.
Instead of expecting such calls to return empty strings, check if the field has already been rendered.

Expand Down
5 changes: 5 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ Finder

* The `Finder::sortByName()` method has a new `$useNaturalSort` argument.

Form
----

* The `scale` option was removed from the `IntegerType`.

FrameworkBundle
---------------

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* added `Symfony\Component\Form\ClearableErrorsInterface`
* deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered
* deprecated the `scale` option of the `IntegerType`

4.1.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addViewTransformer(
new IntegerToLocalizedStringTransformer(
$options['scale'],
null,
$options['grouping'],
$options['rounding_mode']
));
Expand All @@ -37,8 +37,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
// default scale is locale specific (usually around 3)
'scale' => null,
'grouping' => false,
// Integer cast rounds towards 0, so do the same when displaying fractions
'rounding_mode' => IntegerToLocalizedStringTransformer::ROUND_DOWN,
Expand All @@ -55,7 +53,9 @@ public function configureOptions(OptionsResolver $resolver)
IntegerToLocalizedStringTransformer::ROUND_CEILING,
));

$resolver->setDefined('scale');
$resolver->setAllowedTypes('scale', array('null', 'int'));
$resolver->setDeprecated('scale');
}

/**
Expand Down
33 changes: 31 additions & 2 deletions src/Symfony/Component/Form/Tests/Command/DebugCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Command\DebugCommand;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormRegistry;
use Symfony\Component\Form\ResolvedFormTypeFactory;
use Symfony\Component\Form\Tests\Console\Descriptor\FooType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

class DebugCommandTest extends TestCase
{
Expand All @@ -40,10 +42,15 @@ public function testDebugDeprecatedDefaults()
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
$this->assertSame(<<<TXT

Built-in form types (Symfony\Component\Form\Extension\Core\Type)
----------------------------------------------------------------

IntegerType

Service form types
------------------

* Symfony\Component\Form\Tests\Console\Descriptor\FooType
* Symfony\Component\Form\Tests\Command\FooType


TXT
Expand Down Expand Up @@ -147,3 +154,25 @@ private function createCommandTester(array $namespaces = array('Symfony\Componen
return new CommandTester($application->find('debug:form'));
}
}

class FooType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired('foo');
$resolver->setDefined('bar');
$resolver->setDeprecated('bar');
$resolver->setDefault('empty_data', function (Options $options) {
$foo = $options['foo'];

return function (FormInterface $form) use ($foo) {
return $form->getConfig()->getCompound() ? array($foo) : $foo;
};
});
$resolver->setAllowedTypes('foo', 'string');
$resolver->setAllowedValues('foo', array('bar', 'baz'));
$resolver->setNormalizer('foo', function (Options $options, $value) {
return (string) $value;
});
}
}