Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 53c5f41

Browse files
committed
[Form] Allow to disable and customize PercentType symbol
1 parent 9aeaea0 commit 53c5f41

File tree

6 files changed

+34
-45
lines changed

6 files changed

+34
-45
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Twig\Tests\Extension;
1313

14+
use Symfony\Component\Form\Extension\Core\Type\PercentType;
1415
use Symfony\Component\Form\FormError;
1516
use Symfony\Component\Form\Tests\AbstractLayoutTest;
1617

@@ -2175,24 +2176,22 @@ public function testPercent()
21752176

21762177
public function testPercentNoSymbol()
21772178
{
2178-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PercentType', 0.1, array('symbol' => false));
2179-
2180-
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
2179+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => false]);
2180+
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
21812181
'/input
2182-
[@id="my&id"]
2183-
[@type="text"]
2184-
[@name="name"]
2185-
[@class="my&class form-control"]
2186-
[@value="10"]
2182+
[@id="my&id"]
2183+
[@type="text"]
2184+
[@name="name"]
2185+
[@class="my&class form-control"]
2186+
[@value="10"]
21872187
'
21882188
);
21892189
}
21902190

21912191
public function testPercentCustomSymbol()
21922192
{
2193-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PercentType', 0.1, array('symbol' => ''));
2194-
2195-
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
2193+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => '']);
2194+
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
21962195
'/div
21972196
[@class="input-group"]
21982197
[

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap4LayoutTest.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ public function testMoney()
10821082
]);
10831083

10841084
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
1085-
'/div
1085+
'/div
10861086
[@class="input-group"]
10871087
[
10881088
./div
@@ -1108,7 +1108,7 @@ public function testPercent()
11081108
$form = $this->factory->createNamed('name', PercentType::class, 0.1);
11091109

11101110
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
1111-
'/div
1111+
'/div
11121112
[@class="input-group"]
11131113
[
11141114
./input
@@ -1131,25 +1131,23 @@ public function testPercent()
11311131

11321132
public function testPercentNoSymbol()
11331133
{
1134-
$form = $this->factory->createNamed('name', PercentType::class, 0.1, array('symbol' => false));
1135-
1136-
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
1137-
'/input
1138-
[@id="my&id"]
1139-
[@type="text"]
1140-
[@name="name"]
1141-
[@class="my&class form-control"]
1142-
[@value="10"]
1134+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => false]);
1135+
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
1136+
'/input
1137+
[@id="my&id"]
1138+
[@type="text"]
1139+
[@name="name"]
1140+
[@class="my&class form-control"]
1141+
[@value="10"]
11431142
'
11441143
);
11451144
}
11461145

11471146
public function testPercentCustomSymbol()
11481147
{
1149-
$form = $this->factory->createNamed('name', PercentType::class, 0.1, array('symbol' => ''));
1150-
1151-
$this->assertWidgetMatchesXpath($form->createView(), array('id' => 'my&id', 'attr' => array('class' => 'my&class')),
1152-
'/div
1148+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => '']);
1149+
$this->assertWidgetMatchesXpath($form->createView(), ['id' => 'my&id', 'attr' => ['class' => 'my&class']],
1150+
'/div
11531151
[@class="input-group"]
11541152
[
11551153
./input
Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,2 @@
1-
<?php
2-
3-
/*
4-
* This file is part of the Symfony package.
5-
*
6-
* (c) Fabien Potencier <[email protected]>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
12-
$symbol = $symbol !== false ? (!empty($symbol) ? ' ' . $symbol : ' %') : '';
13-
echo $view['form']->block($form, 'form_widget_simple', ['type' => isset($type) ? $type : 'text']) . $symbol; ?>
1+
<?php $symbol = false !== $symbol ? ($symbol ? ' '.$symbol : ' %') : '' ?>
2+
<?php echo $view['form']->block($form, 'form_widget_simple', ['type' => isset($type) ? $type : 'text']).$symbol ?>

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CHANGELOG
44
4.3.0
55
-----
66

7-
* added a `symbol` option to the `PercentType` that allows to disable the output of the percent character
7+
* added a `symbol` option to the `PercentType` that allows to disable or customize the output of the percent character
88
* Using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled is deprecated.
99
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
1010
exception in 5.0.

src/Symfony/Component/Form/Extension/Core/Type/PercentType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function configureOptions(OptionsResolver $resolver)
5454
]);
5555

5656
$resolver->setAllowedTypes('scale', 'int');
57-
$resolver->setAllowedTypes('symbol', array('bool', 'string'));
57+
$resolver->setAllowedTypes('symbol', ['bool', 'string']);
5858
}
5959

6060
/**

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Tests;
1313

1414
use PHPUnit\Framework\SkippedTestError;
15+
use Symfony\Component\Form\Extension\Core\Type\PercentType;
1516
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
1617
use Symfony\Component\Form\FormError;
1718
use Symfony\Component\Form\FormView;
@@ -1947,9 +1948,10 @@ public function testPercent()
19471948

19481949
public function testPercentNoSymbol()
19491950
{
1950-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PercentType', 0.1, array('symbol' => false));
1951+
$this->requiresFeatureSet(403);
19511952

1952-
$this->assertWidgetMatchesXpath($form->createView(), array(),
1953+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => false]);
1954+
$this->assertWidgetMatchesXpath($form->createView(), [],
19531955
'/input
19541956
[@type="text"]
19551957
[@name="name"]
@@ -1961,9 +1963,10 @@ public function testPercentNoSymbol()
19611963

19621964
public function testPercentCustomSymbol()
19631965
{
1964-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\PercentType', 0.1, array('symbol' => ''));
1966+
$this->requiresFeatureSet(403);
19651967

1966-
$this->assertWidgetMatchesXpath($form->createView(), array(),
1968+
$form = $this->factory->createNamed('name', PercentType::class, 0.1, ['symbol' => '']);
1969+
$this->assertWidgetMatchesXpath($form->createView(), [],
19671970
'/input
19681971
[@type="text"]
19691972
[@name="name"]

0 commit comments

Comments
 (0)