8000 bug #29926 [Form] Changed UrlType input type to text when default_pro… · symfony/symfony@e3b010f · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit e3b010f

Browse files
bug #29926 [Form] Changed UrlType input type to text when default_protocol is not null (MatTheCat)
This PR was merged into the 3.4 branch. Discussion ---------- [Form] Changed UrlType input type to text when default_protocol is not null | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29690 | License | MIT | Doc PR | replaces #29691 Commits ------- 2791edf [Form] Changed UrlType input type to text when default_protocol is not null
2 parents 13d1d76 + 2791edf commit e3b010f

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,13 +2385,29 @@ public function testTimezoneWithPlaceholder()
23852385
);
23862386
}
23872387

2388-
public function testUrl()
2388+
public function testUrlWithDefaultProtocol()
23892389
{
23902390
$url = 'http://www.google.com?foo1=bar1&foo2=bar2';
2391-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url);
2391+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_protocol' => 'http']);
23922392

23932393
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
23942394
'/input
2395+
[@type="text"]
2396+
[@name="name"]
2397+
[@class="my&class form-control"]
2398+
[@value="http://www.google.com?foo1=bar1&foo2=bar2"]
2399+
[@inputmode="url"]
2400+
'
2401+
);
2402+
}
2403+
2404+
public function testUrlWithoutDefaultProtocol()
2405+
{
2406+
$url = 'http://www.google.com?foo1=bar1&foo2=bar2';
2407+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_protocol' => null]);
2408+
2409+
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
2410+
'/input
23952411
[@type="url"]
23962412
[@name="name"]
23972413
[@class="my&class form-control"]

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/asset": "~2.8|~3.0|~4.0",
2424
"symfony/dependency-injection": "~2.8|~3.0|~4.0",
2525
"symfony/finder": "~2.8|~3.0|~4.0",
26-
"symfony/form": "^3.4.16|^4.1.5",
26+
"symfony/form": "^3.4.22|~4.1.11|^4.2.3",
2727
"symfony/http-foundation": "^3.3.11|~4.0",
2828
"symfony/http-kernel": "~3.2|~4.0",
2929
"symfony/polyfill-intl-icu": "~1.0",

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"symfony/css-selector": "~2.8|~3.0|~4.0",
4040
"symfony/dom-crawler": "~2.8|~3.0|~4.0",
4141
"symfony/polyfill-intl-icu": "~1.0",
42-
"symfony/form": "~3.4|~4.0",
42+
"symfony/form": "^3.4.22|~4.1.11|^4.2.3",
4343
"symfony/expression-language": "~2.8|~3.0|~4.0",
4444
"symfony/process": "~2.8|~3.0|~4.0",
4545
"symfony/security-core": "~3.2|~4.0",

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Form\AbstractType;
1515
use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener;
1616
use Symfony\Component\Form\FormBuilderInterface;
17+
use Symfony\Component\Form\FormInterface;
18+
use Symfony\Component\Form\FormView;
1719
use Symfony\Component\OptionsResolver\OptionsResolver;
1820

1921
class UrlType extends AbstractType
@@ -28,6 +30,17 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2830
}
2931
}
3032

33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function buildView(FormView $view, FormInterface $form, array $options)
37+
{
38+
if ($options['default_protocol']) {
39+
$view->vars['attr']['inputmode'] = 'url';
40+
$view->vars['type'] = 'text';
41+
}
42+
}
43+
3144
/**
3245
* {@inheritdoc}
3346
*/

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,10 +2170,25 @@ public function testTimezoneWithPlaceholder()
21702170
);
21712171
}
21722172

2173-
public function testUrl()
2173+
public function testUrlWithDefaultProtocol()
21742174
{
21752175
$url = 'http://www.google.com?foo1=bar1&foo2=bar2';
2176-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url);
2176+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_pr 1E80 otocol' => 'http']);
2177+
2178+
$this->assertWidgetMatchesXpath($form->createView(), [],
2179+
'/input
2180+
[@type="text"]
2181+
[@name="name"]
2182+
[@value="http://www.google.com?foo1=bar1&foo2=bar2"]
2183+
[@inputmode="url"]
2184+
'
2185+
);
2186+
}
2187+
2188+
public function testUrlWithoutDefaultProtocol()
2189+
{
2190+
$url = 'http://www.google.com?foo1=bar1&foo2=bar2';
2191+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_protocol' => null]);
21772192

21782193
$this->assertWidgetMatchesXpath($form->createView(), [],
21792194
'/input

0 commit comments

Comments
 (0)
0