feature #22679 [Form] Add tel and color types (apetitpa)

This PR was squashed before being merged into the 3.4 branch (closes #22679).

Discussion
----------

[Form] Add tel and color types

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22596
| License       | MIT
| Doc PR        | not provided yet

Commits
-------

5b07ca7 [Form] Add tel and color types
This commit is contained in:
Nicolas Grekas 2017-10-02 14:59:32 +02:00
commit 579e3b3bb5
11 changed files with 148 additions and 8 deletions

View File

@ -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 -%}

View File

@ -0,0 +1 @@
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'color'));

View File

@ -0,0 +1 @@
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : 'tel'));

View File

@ -77,6 +77,8 @@ class CoreExtension extends AbstractExtension
new Type\SubmitType(),
new Type\ResetType(),
new Type\CurrencyType(),
new Type\TelType(),
new Type\ColorType(),
);
}
}

View File

@ -0,0 +1,33 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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';
}
}

View File

@ -0,0 +1,33 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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';
}
}

View File

@ -2468,4 +2468,34 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
// foo="foo"
$this->assertSame('<button type="button" id="button" name="button" foo="foo" class="btn-default btn">[trans]Button[/trans]</button>', $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"]
'
);
}
}

View File

@ -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"]
'
);
}
}

View File

@ -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",

View File

@ -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
------------------

View File

@ -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.",