Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[WIP] Add doc for tel type #4040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions reference/constraints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Validation Constraints Reference
constraints/Regex
constraints/Ip
constraints/Uuid
constraints/PhoneNumber

constraints/Range

Expand Down
107 changes: 107 additions & 0 deletions reference/constraints/PhoneNumber.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
Email
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be PhoneNumber, shouldn't it?

=====

Validates that a value is a valid phone number.

+----------------+---------------------------------------------------------------------------+
| Applies to | :ref:`property or method <validation-property-target>` |
+----------------+---------------------------------------------------------------------------+
| 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

<!-- src/Acme/BlogBundle/Resources/config/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">

<class name="Acme\BlogBundle\Entity\Author">
<property name="phoneNumber">
<constraint name="PhoneNumber">
<option name="message">This value is not a valid phone number.</option>
<option name="region">FR</option>
</constraint>
</property>
</class>
</constraint-mapping>

.. 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be moved to the top (before the introduction paragraph)


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.
1 change: 1 addition & 0 deletions reference/constraints/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ String Constraints
* :doc:`Regex </reference/constraints/Regex>`
* :doc:`Ip </reference/constraints/Ip>`
* :doc:`Uuid</reference/constraints/Uuid>`
* :doc:`PhoneNumber </reference/constraints/PhoneNumber>`

Number Constraints
~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions reference/forms/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Form Types Reference
types/percent
types/search
types/url
types/tel

types/choice
types/entity
Expand Down
1 change: 1 addition & 0 deletions reference/forms/types/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Text Fields
* :doc:`percent </reference/forms/types/percent>`
* :doc:`search </reference/forms/types/search>`
* :doc:`url </reference/forms/types/url>`
* :doc:`tel </reference/forms/types/tel>`

Choice Fields
~~~~~~~~~~~~~
Expand Down
60 changes: 60 additions & 0 deletions reference/forms/types/tel.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.. index::
single: Forms; Fields; tel

Tel Field Type
===============

.. versionadded:: 2.6
The Tel field type was introduced in Symfony 2.6.

The tel field represents a text field for entering a telephone number.

+-------------+--------------------------------------------------------------------+
| Rendered as | ``input`` ``tel`` field |
+-------------+--------------------------------------------------------------------+
| Inherited | - `empty_data`_ |
| options | - `required`_ |
| | - `label`_ |
| | - `label_attr`_ |
| | - `data`_ |
| | - `trim`_ |
| | - `read_only`_ |
| | - `disabled`_ |
| | - `error_bubbling`_ |
| | - `error_mapping`_ |
| | - `mapped`_ |
+-------------+--------------------------------------------------------------------+
| Parent type | :doc:`form </reference/forms/types/form>` |
+-------------+--------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\TelType` |
+-------------+--------------------------------------------------------------------+


Inherited Options
-----------------

These options inherit from the :doc:`form </reference/forms/types/form>` type:

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

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