From 161d5754c8f80aa278d22249dc74ad641c746110 Mon Sep 17 00:00:00 2001 From: Mathieu Lechat Date: Wed, 26 Dec 2018 17:27:02 +0100 Subject: [PATCH 1/5] [Form] Changed UrlType input type to text when default_protocol is not null --- .../AbstractBootstrap3LayoutTest.php | 19 +++++++++++++++++-- .../Form/Extension/Core/Type/UrlType.php | 10 ++++++++++ .../Form/Tests/AbstractLayoutTest.php | 18 ++++++++++++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php index ae62a40f604f7..899875cf1ab32 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php @@ -2385,13 +2385,28 @@ public function testTimezoneWithPlaceholder() ); } - 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, array('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"] +' + ); + } + + 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, array('default_protocol' => null)); + + $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')), + '/input [@type="url"] [@name="name"] [@class="my&class form-control"] diff --git a/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php b/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php index 17460688b7fd6..1356a196b34fa 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php @@ -14,6 +14,8 @@ 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,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) } } + /** + * {@inheritdoc} + */ + public function buildView(FormView $view, FormInterface $form, array $options) + { + $view->vars['type'] = $options['default_protocol'] ? 'text' : 'url'; + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index bb7fc197abfce..dd86e87f309e3 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -2170,10 +2170,24 @@ public function testTimezoneWithPlaceholder() ); } - 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, array('default_protocol' => 'http')); + + $this->assertWidgetMatchesXpath($form->createView(), array(), +'/input + [@type="text"] + [@name="name"] + [@value="http://www.google.com?foo1=bar1&foo2=bar2"] +' + ); + } + + 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, array('default_protocol' => null)); $this->assertWidgetMatchesXpath($form->createView(), [], '/input From 1007fc240039a6776ba013ce9f995d455447b22f Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 1 Jan 2019 15:00:22 +0100 Subject: [PATCH 2/5] fix lowest version constraints --- src/Symfony/Bridge/Twig/composer.json | 2 +- src/Symfony/Bundle/FrameworkBundle/composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index 7d646c0010437..58e90971bec11 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -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", diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index c1aad683ad69b..c8ed98787e15e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -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", From 09675b67db00138ef702ba1c6c22123463a4a499 Mon Sep 17 00:00:00 2001 From: Mathieu Lechat Date: Thu, 3 Jan 2019 14:12:49 +0100 Subject: [PATCH 3/5] Add inputmode attribute --- src/Symfony/Component/Form/Extension/Core/Type/UrlType.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php b/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php index 1356a196b34fa..39b9d2d20828c 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php @@ -35,7 +35,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) */ public function buildView(FormView $view, FormInterface $form, array $options) { - $view->vars['type'] = $options['default_protocol'] ? 'text' : 'url'; + if ($options['default_protocol']) { + $view->vars['attr']['inputmode'] = 'url'; + $view->vars['type'] = 'text'; + } } /** From e23845a4992618c825c681d45a42807902344e77 Mon Sep 17 00:00:00 2001 From: Mathieu Lechat Date: Mon, 7 Jan 2019 13:30:05 +0100 Subject: [PATCH 4/5] Test inputmode too --- .../Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php | 1 + src/Symfony/Component/Form/Tests/AbstractLayoutTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php index 899875cf1ab32..7217cc319b913 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php @@ -2396,6 +2396,7 @@ public function testUrlWithDefaultProtocol() [@name="name"] [@class="my&class form-control"] [@value="http://www.google.com?foo1=bar1&foo2=bar2"] + [@inputmode="url"] ' ); } diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index dd86e87f309e3..66adcd15bc216 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -2180,6 +2180,7 @@ public function testUrlWithDefaultProtocol() [@type="text"] [@name="name"] [@value="http://www.google.com?foo1=bar1&foo2=bar2"] + [@inputmode="url"] ' ); } From 3411766880dfc250d574a24ca08059f18956ad85 Mon Sep 17 00:00:00 2001 From: Mathieu Lechat Date: Tue, 8 Jan 2019 11:05:45 +0100 Subject: [PATCH 5/5] Update CS --- .../Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php | 6 +++--- src/Symfony/Component/Form/Tests/AbstractLayoutTest.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php index 7217cc319b913..ebfb105826b33 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php @@ -2388,7 +2388,7 @@ public function testTimezoneWithPlaceholder() 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, array('default_protocol' => 'http')); + $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 @@ -2404,9 +2404,9 @@ public function testUrlWithDefaultProtocol() 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, array('default_protocol' => null)); + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_protocol' => null]); - $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')), + $this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']], '/input [@type="url"] [@name="name"] diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index 66adcd15bc216..0e749b780c784 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -2173,9 +2173,9 @@ public function testTimezoneWithPlaceholder() 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, array('default_protocol' => 'http')); + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_protocol' => 'http']); - $this->assertWidgetMatchesXpath($form->createView(), array(), + $this->assertWidgetMatchesXpath($form->createView(), [], '/input [@type="text"] [@name="name"] @@ -2188,7 +2188,7 @@ public function testUrlWithDefaultProtocol() 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, array('default_protocol' => null)); + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_protocol' => null]); $this->assertWidgetMatchesXpath($form->createView(), [], '/input