-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4469cf6
add doc for tel type
lepiaf f5510cd
add reference
lepiaf 7dde446
change next release version
lepiaf edb9cca
change next release version
lepiaf b5accac
add note to third-party library
lepiaf 9ed02cb
add PhoneNumber constraint
lepiaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
===== | ||
|
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ Form Types Reference | |
types/percent | ||
types/search | ||
types/url | ||
types/tel | ||
|
||
types/choice | ||
types/entity | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?