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
-------
2791edf1fb
[Form] Changed UrlType input type to text when default_protocol is not null
This commit is contained in:
commit
e3b010fe16
@ -2385,13 +2385,29 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
);
|
||||
}
|
||||
|
||||
public function testUrl()
|
||||
public function testUrlWithDefaultProtocol()
|
||||
{
|
||||
$url = 'http://www.google.com?foo1=bar1&foo2=bar2';
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url);
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_protocol' => 'http']);
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
|
||||
'/input
|
||||
[@type="text"]
|
||||
[@name="name"]
|
||||
[@class="my&class form-control"]
|
||||
[@value="http://www.google.com?foo1=bar1&foo2=bar2"]
|
||||
[@inputmode="url"]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testUrlWithoutDefaultProtocol()
|
||||
{
|
||||
$url = 'http://www.google.com?foo1=bar1&foo2=bar2';
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_protocol' => null]);
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
|
||||
'/input
|
||||
[@type="url"]
|
||||
[@name="name"]
|
||||
[@class="my&class form-control"]
|
||||
|
@ -23,7 +23,7 @@
|
||||
"symfony/asset": "~2.8|~3.0|~4.0",
|
||||
"symfony/dependency-injection": "~2.8|~3.0|~4.0",
|
||||
"symfony/finder": "~2.8|~3.0|~4.0",
|
||||
"symfony/form": "^3.4.16|^4.1.5",
|
||||
"symfony/form": "^3.4.22|~4.1.11|^4.2.3",
|
||||
"symfony/http-foundation": "^3.3.11|~4.0",
|
||||
"symfony/http-kernel": "~3.2|~4.0",
|
||||
"symfony/polyfill-intl-icu": "~1.0",
|
||||
|
@ -39,7 +39,7 @@
|
||||
"symfony/css-selector": "~2.8|~3.0|~4.0",
|
||||
"symfony/dom-crawler": "~2.8|~3.0|~4.0",
|
||||
"symfony/polyfill-intl-icu": "~1.0",
|
||||
"symfony/form": "~3.4|~4.0",
|
||||
"symfony/form": "^3.4.22|~4.1.11|^4.2.3",
|
||||
"symfony/expression-language": "~2.8|~3.0|~4.0",
|
||||
"symfony/process": "~2.8|~3.0|~4.0",
|
||||
"symfony/security-core": "~3.2|~4.0",
|
||||
|
@ -14,6 +14,8 @@ namespace Symfony\Component\Form\Extension\Core\Type;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class UrlType extends AbstractType
|
||||
@ -28,6 +30,17 @@ class UrlType extends AbstractType
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
if ($options['default_protocol']) {
|
||||
$view->vars['attr']['inputmode'] = 'url';
|
||||
$view->vars['type'] = 'text';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -2170,10 +2170,25 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testUrl()
|
||||
public function testUrlWithDefaultProtocol()
|
||||
{
|
||||
$url = 'http://www.google.com?foo1=bar1&foo2=bar2';
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url);
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_protocol' => 'http']);
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), [],
|
||||
'/input
|
||||
[@type="text"]
|
||||
[@name="name"]
|
||||
[@value="http://www.google.com?foo1=bar1&foo2=bar2"]
|
||||
[@inputmode="url"]
|
||||
'
|
||||
);
|
||||
}
|
||||
|
||||
public function testUrlWithoutDefaultProtocol()
|
||||
{
|
||||
$url = 'http://www.google.com?foo1=bar1&foo2=bar2';
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_protocol' => null]);
|
||||
|
||||
$this->assertWidgetMatchesXpath($form->createView(), [],
|
||||
'/input
|
||||
|
Reference in New Issue
Block a user