From 4469cf6920dc9e2b9f3add9464640a14bbce4f9f Mon Sep 17 00:00:00 2001 From: Thierry Thuon Date: Sun, 20 Jul 2014 13:56:47 +0200 Subject: [PATCH 1/6] add doc for tel type --- reference/forms/types/tel.rst | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 reference/forms/types/tel.rst diff --git a/reference/forms/types/tel.rst b/reference/forms/types/tel.rst new file mode 100644 index 00000000000..0b29f80a614 --- /dev/null +++ b/reference/forms/types/tel.rst @@ -0,0 +1,58 @@ +.. index:: + single: Forms; Fields; tel + +tel Field Type +=============== + +The tel field represents a text field for entering a telephone number. + ++-------------+--------------------------------------------------------------------+ +| Rendered as | ``input`` ``tel`` field | ++-------------+--------------------------------------------------------------------+ +| Inherited | - `max_length`_ (deprecated as of 2.5) | +| options | - `empty_data`_ | +| | - `required`_ | +| | - `label`_ | +| | - `label_attr`_ | +| | - `data`_ | +| | - `trim`_ | +| | - `read_only`_ | +| | - `disabled`_ | +| | - `error_bubbling`_ | +| | - `error_mapping`_ | +| | - `mapped`_ | ++-------------+--------------------------------------------------------------------+ +| Parent type | :doc:`form ` | ++-------------+--------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\TelType` | ++-------------+--------------------------------------------------------------------+ + + +Inherited Options +----------------- + +These options inherit from the :doc:`form ` type: + +.. include:: /reference/forms/types/options/max_length.rst.inc + +.. include:: /reference/forms/types/options/empty_data.rst.inc + +.. include:: /reference/forms/types/options/required.rst.inc + +.. include:: /reference/forms/types/options/label.rst.inc + +.. include:: /reference/forms/types/options/label_attr.rst.inc + +.. include:: /reference/forms/types/options/data.rst.inc + +.. include:: /reference/forms/types/options/trim.rst.inc + +.. include:: /reference/forms/types/options/read_only.rst.inc + +.. include:: /reference/forms/types/options/disabled.rst.inc + +.. include:: /reference/forms/types/options/error_bubbling.rst.inc + +.. include:: /reference/forms/types/options/error_mapping.rst.inc + +.. include:: /reference/forms/types/options/mapped.rst.inc From f5510cd2cf3bd1c079bdbacbde404e0cd6620899 Mon Sep 17 00:00:00 2001 From: Thierry Thuon Date: Sun, 20 Jul 2014 15:40:01 +0200 Subject: [PATCH 2/6] add reference --- reference/forms/types.rst | 1 + reference/forms/types/map.rst.inc | 1 + reference/forms/types/tel.rst | 16 ++++++++-------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/reference/forms/types.rst b/reference/forms/types.rst index 82b22bde79c..bcf73d768ab 100644 --- a/reference/forms/types.rst +++ b/reference/forms/types.rst @@ -18,6 +18,7 @@ Form Types Reference types/percent types/search types/url + types/tel types/choice types/entity diff --git a/reference/forms/types/map.rst.inc b/reference/forms/types/map.rst.inc index b4362b3f318..df6679dfc24 100644 --- a/reference/forms/types/map.rst.inc +++ b/reference/forms/types/map.rst.inc @@ -11,6 +11,7 @@ Text Fields * :doc:`percent ` * :doc:`search ` * :doc:`url ` +* :doc:`tel ` Choice Fields ~~~~~~~~~~~~~ diff --git a/reference/forms/types/tel.rst b/reference/forms/types/tel.rst index 0b29f80a614..d81d557d036 100644 --- a/reference/forms/types/tel.rst +++ b/reference/forms/types/tel.rst @@ -1,17 +1,19 @@ .. index:: single: Forms; Fields; tel -tel Field Type +Tel Field Type =============== +.. versionadded:: 2.7 + The Tel field type was introduced in Symfony 2.7. + The tel field represents a text field for entering a telephone number. +-------------+--------------------------------------------------------------------+ -| Rendered as | ``input`` ``tel`` field | +| Rendered as | ``input`` ``tel`` field | +-------------+--------------------------------------------------------------------+ -| Inherited | - `max_length`_ (deprecated as of 2.5) | -| options | - `empty_data`_ | -| | - `required`_ | +| Inherited | - `empty_data`_ | +| options | - `required`_ | | | - `label`_ | | | - `label_attr`_ | | | - `data`_ | @@ -24,7 +26,7 @@ The tel field represents a text field for entering a telephone number. +-------------+--------------------------------------------------------------------+ | Parent type | :doc:`form ` | +-------------+--------------------------------------------------------------------+ -| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\TelType` | +| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\TelType` | +-------------+--------------------------------------------------------------------+ @@ -33,8 +35,6 @@ Inherited Options These options inherit from the :doc:`form ` type: -.. include:: /reference/forms/types/options/max_length.rst.inc - .. include:: /reference/forms/types/options/empty_data.rst.inc .. include:: /reference/forms/types/options/required.rst.inc From 7dde446d53cc0e5d34d5792d36913d33ebe82912 Mon Sep 17 00:00:00 2001 From: Thierry Thuon Date: Sun, 20 Jul 2014 15:43:39 +0200 Subject: [PATCH 3/6] change next release version --- reference/forms/types/tel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/forms/types/tel.rst b/reference/forms/types/tel.rst index d81d557d036..b6f841ec6a7 100644 --- a/reference/forms/types/tel.rst +++ b/reference/forms/types/tel.rst @@ -4,7 +4,7 @@ Tel Field Type =============== -.. versionadded:: 2.7 +.. versionadded:: 2.6 The Tel field type was introduced in Symfony 2.7. The tel field represents a text field for entering a telephone number. From edb9cca7dbe87212fc7727eae196ac064504ed1f Mon Sep 17 00:00:00 2001 From: Thierry Thuon Date: Sun, 20 Jul 2014 16:30:42 +0200 Subject: [PATCH 4/6] change next release version --- reference/forms/types/tel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/forms/types/tel.rst b/reference/forms/types/tel.rst index b6f841ec6a7..fb674b586b7 100644 --- a/reference/forms/types/tel.rst +++ b/reference/forms/types/tel.rst @@ -5,7 +5,7 @@ Tel Field Type =============== .. versionadded:: 2.6 - The Tel field type was introduced in Symfony 2.7. + The Tel field type was introduced in Symfony 2.6. The tel field represents a text field for entering a telephone number. From b5accac4250a16061535bf3f7f0f404373aa1494 Mon Sep 17 00:00:00 2001 From: Thierry Thuon Date: Mon, 21 Jul 2014 21:49:46 +0200 Subject: [PATCH 5/6] add note to third-party library --- reference/forms/types/tel.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reference/forms/types/tel.rst b/reference/forms/types/tel.rst index fb674b586b7..f767cbe29bd 100644 --- a/reference/forms/types/tel.rst +++ b/reference/forms/types/tel.rst @@ -56,3 +56,5 @@ These options inherit from the :doc:`form ` type: .. include:: /reference/forms/types/options/error_mapping.rst.inc .. include:: /reference/forms/types/options/mapped.rst.inc + +.. note:: Tel field rely on third-party library : https://github.com/giggsey/libphonenumber-for-php. It's require and you should install it via Composer. From 9ed02cb0864299e4e2a356853f79f7c3d8c8f919 Mon Sep 17 00:00:00 2001 From: Thierry Thuon Date: Mon, 21 Jul 2014 22:06:50 +0200 Subject: [PATCH 6/6] add PhoneNumber constraint --- reference/constraints.rst | 1 + reference/constraints/PhoneNumber.rst | 107 ++++++++++++++++++++++++++ reference/constraints/map.rst.inc | 1 + 3 files changed, 109 insertions(+) create mode 100644 reference/constraints/PhoneNumber.rst diff --git a/reference/constraints.rst b/reference/constraints.rst index ac8ef5ae33c..25267ac0357 100644 --- a/reference/constraints.rst +++ b/reference/constraints.rst @@ -19,6 +19,7 @@ Validation Constraints Reference constraints/Regex constraints/Ip constraints/Uuid + constraints/PhoneNumber constraints/Range diff --git a/reference/constraints/PhoneNumber.rst b/reference/constraints/PhoneNumber.rst new file mode 100644 index 00000000000..3a4a9612ca9 --- /dev/null +++ b/reference/constraints/PhoneNumber.rst @@ -0,0 +1,107 @@ +Email +===== + +Validates that a value is a valid phone number. + ++----------------+---------------------------------------------------------------------------+ +| Applies to | :ref:`property or method ` | ++----------------+---------------------------------------------------------------------------+ +| Options | - `region`_ | ++----------------+---------------------------------------------------------------------------+ +| Class | :class:`Symfony\\Component\\Validator\\Constraints\\PhoneNumber` | ++----------------+---------------------------------------------------------------------------+ +| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\PhoneNumberValidator` | ++----------------+---------------------------------------------------------------------------+ + +Basic Usage +----------- + +.. configuration-block:: + + .. code-block:: yaml + + # src/BlogBundle/Resources/config/validation.yml + Acme\BlogBundle\Entity\Author: + properties: + phoneNumber: + - PhoneNumber: + message: This value is not a valid phone number. + region: FR + + .. code-block:: php-annotations + + // src/Acme/BlogBundle/Entity/Author.php + namespace Acme\BlogBundle\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + /** + * @Assert\PhoneNumber( + * message = "This value is not a valid phone number.", + * region = FR + * ) + */ + protected $phoneNumber; + } + + .. code-block:: xml + + + + + + + + + + + + + + + + .. code-block:: php + + // src/Acme/BlogBundle/Entity/Author.php + namespace Acme\BlogBundle\Entity; + + use Symfony\Component\Validator\Mapping\ClassMetadata; + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + public static function loadValidatorMetadata(ClassMetadata $metadata) + { + $metadata->addPropertyConstraint('phoneNumber', new Assert\PhoneNumber(array( + 'message' => 'This value is not a valid phone number.', + 'region' => FR, + ))); + } + } + +Options +------- + +.. versionadded:: 2.6 + The PhoneNumber constraint was introduced in Symfony 2.6. + +region +~~~~~~ + +**type**: ``string`` **default**: ``null`` + +When null, it does not parse local phone number. If you entered a value (eg: 'FR'), +it will be able to parse and validate phone number. + +message +~~~~~~~ + +**type**: ``string`` **default**: ``This value is not a valid phone number.`` + +This message is shown if the underlying data is not a valid phone number. + +.. note:: PhoneNumber constraint rely on third-party library : https://github.com/giggsey/libphonenumber-for-php. It's require and you should install it via Composer. diff --git a/reference/constraints/map.rst.inc b/reference/constraints/map.rst.inc index 686ad22bca5..0cce2bf4fe8 100644 --- a/reference/constraints/map.rst.inc +++ b/reference/constraints/map.rst.inc @@ -21,6 +21,7 @@ String Constraints * :doc:`Regex ` * :doc:`Ip ` * :doc:`Uuid` +* :doc:`PhoneNumber ` Number Constraints ~~~~~~~~~~~~~~~~~~