diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 2a0dd466bb..52525c061c 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -239,6 +239,16 @@ {{ block('button_widget') }} {%- endblock reset_widget -%} +{%- block tel_widget -%} + {%- set type = type|default('tel') -%} + {{ block('form_widget_simple') }} +{%- endblock tel_widget -%} + +{%- block color_widget -%} + {%- set type = type|default('color') -%} + {{ block('form_widget_simple') }} +{%- endblock color_widget -%} + {# Labels #} {%- block form_label -%} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/color_widget.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/color_widget.html.php new file mode 100644 index 0000000000..10a8cdf149 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/color_widget.html.php @@ -0,0 +1 @@ +block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'color')); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/tel_widget.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/tel_widget.html.php new file mode 100644 index 0000000000..7779538127 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/tel_widget.html.php @@ -0,0 +1 @@ +block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'tel')); diff --git a/src/Symfony/Component/Form/Extension/Core/CoreExtension.php b/src/Symfony/Component/Form/Extension/Core/CoreExtension.php index 156d556880..857792ad9f 100644 --- a/src/Symfony/Component/Form/Extension/Core/CoreExtension.php +++ b/src/Symfony/Component/Form/Extension/Core/CoreExtension.php @@ -77,6 +77,8 @@ class CoreExtension extends AbstractExtension new Type\SubmitType(), new Type\ResetType(), new Type\CurrencyType(), + new Type\TelType(), + new Type\ColorType(), ); } } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ColorType.php b/src/Symfony/Component/Form/Extension/Core/Type/ColorType.php new file mode 100644 index 0000000000..9c2734ead6 --- /dev/null +++ b/src/Symfony/Component/Form/Extension/Core/Type/ColorType.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Extension\Core\Type; + +use Symfony\Component\Form\AbstractType; + +class ColorType extends AbstractType +{ + /** + * {@inheritdoc} + */ + public function getParent() + { + return TextType::class; + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'color'; + } +} diff --git a/src/Symfony/Component/Form/Extension/Core/Type/TelType.php b/src/Symfony/Component/Form/Extension/Core/Type/TelType.php new file mode 100644 index 0000000000..de74a3ed37 --- /dev/null +++ b/src/Symfony/Component/Form/Extension/Core/Type/TelType.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Extension\Core\Type; + +use Symfony\Component\Form\AbstractType; + +class TelType extends AbstractType +{ + /** + * {@inheritdoc} + */ + public function getParent() + { + return TextType::class; + } + + /** + * {@inheritdoc} + */ + public function getBlockPrefix() + { + return 'tel'; + } +} diff --git a/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php index 09138b1da7..6415d7f4a9 100644 --- a/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractBootstrap3LayoutTest.php @@ -2468,4 +2468,34 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest // foo="foo" $this->assertSame('', $html); } + + public function testTel() + { + $tel = '0102030405'; + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TelType', $tel); + + $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')), + '/input + [@type="tel"] + [@name="name"] + [@class="my&class form-control"] + [@value="0102030405"] +' + ); + } + + public function testColor() + { + $color = '#0000ff'; + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ColorType', $color); + + $this->assertWidgetMatchesXpath($form->createView(), array('attr' => array('class' => 'my&class')), + '/input + [@type="color"] + [@name="name"] + [@class="my&class form-control"] + [@value="#0000ff"] +' + ); + } } diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index db6c64d54e..98d2d48cbe 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -2463,4 +2463,32 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase $this->assertMatchesXpath($html, '/form//input[@title="Foo"]'); $this->assertMatchesXpath($html, '/form//input[@placeholder="Bar"]'); } + + public function testTel() + { + $tel = '0102030405'; + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TelType', $tel); + + $this->assertWidgetMatchesXpath($form->createView(), array(), + '/input + [@type="tel"] + [@name="name"] + [@value="0102030405"] +' + ); + } + + public function testColor() + { + $color = '#0000ff'; + $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ColorType', $color); + + $this->assertWidgetMatchesXpath($form->createView(), array(), + '/input + [@type="color"] + [@name="name"] + [@value="#0000ff"] +' + ); + } } diff --git a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/defaults_1.json b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/defaults_1.json index 565c17601e..99858a2f99 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/defaults_1.json +++ b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/defaults_1.json @@ -5,6 +5,7 @@ "Symfony\\Component\\Form\\Extension\\Core\\Type\\CheckboxType", "Symfony\\Component\\Form\\Extension\\Core\\Type\\ChoiceType", "Symfony\\Component\\Form\\Extension\\Core\\Type\\CollectionType", + "Symfony\\Component\\Form\\Extension\\Core\\Type\\ColorType", "Symfony\\Component\\Form\\Extension\\Core\\Type\\CountryType", "Symfony\\Component\\Form\\Extension\\Core\\Type\\CurrencyType", "Symfony\\Component\\Form\\Extension\\Core\\Type\\DateIntervalType", @@ -27,6 +28,7 @@ "Symfony\\Component\\Form\\Extension\\Core\\Type\\ResetType", "Symfony\\Component\\Form\\Extension\\Core\\Type\\SearchType", "Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType", + "Symfony\\Component\\Form\\Extension\\Core\\Type\\TelType", "Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType", "Symfony\\Component\\Form\\Extension\\Core\\Type\\TextareaType", "Symfony\\Component\\Form\\Extension\\Core\\Type\\TimeType", diff --git a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/defaults_1.txt b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/defaults_1.txt index dd08d5f7a6..52a579ac43 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/defaults_1.txt +++ b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/defaults_1.txt @@ -3,12 +3,12 @@ ---------------------------------------------------------------- BirthdayType, ButtonType, CheckboxType, ChoiceType, CollectionType - CountryType, CurrencyType, DateIntervalType, DateTimeType, DateType - EmailType, FileType, FormType, HiddenType, IntegerType - LanguageType, LocaleType, MoneyType, NumberType, PasswordType - PercentType, RadioType, RangeType, RepeatedType, ResetType - SearchType, SubmitType, TextType, TextareaType, TimeType - TimezoneType, UrlType + ColorType, CountryType, CurrencyType, DateIntervalType, DateTimeType + DateType, EmailType, FileType, FormType, HiddenType + IntegerType, LanguageType, LocaleType, MoneyType, NumberType + PasswordType, PercentType, RadioType, RangeType, RepeatedType + ResetType, SearchType, SubmitType, TelType, TextType + TextareaType, TimeType, TimezoneType, UrlType Service form types ------------------ diff --git a/src/Symfony/Component/Form/composer.json b/src/Symfony/Component/Form/composer.json index 77fc3e565f..4106c65890 100644 --- a/src/Symfony/Component/Form/composer.json +++ b/src/Symfony/Component/Form/composer.json @@ -39,9 +39,9 @@ "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0", "symfony/dependency-injection": "<3.3", "symfony/doctrine-bridge": "<2.7", - "symfony/framework-bundle": "<2.7", + "symfony/framework-bundle": "<3.4", "symfony/http-kernel": "<3.3.5", - "symfony/twig-bridge": "<2.7" + "symfony/twig-bridge": "<3.4" }, "suggest": { "symfony/validator": "For form validation.",