From 676e7620b4878f2da835cf93c5621befee711acd Mon Sep 17 00:00:00 2001 From: Ben Huebscher Date: Tue, 5 May 2015 17:50:53 -0700 Subject: [PATCH 1/3] Improve Choice Validation Constraint Example Example came off sounding transphobic. Added "other" option. --- book/validation.rst | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/book/validation.rst b/book/validation.rst index eb8e4c5d3dd..a9dc819f7f8 100644 --- a/book/validation.rst +++ b/book/validation.rst @@ -329,7 +329,7 @@ Some constraints, like :doc:`NotBlank `, are simple whereas others, like the :doc:`Choice ` constraint, have several configuration options available. Suppose that the ``Author`` class has another property called ``gender`` that can be set to either -"male" or "female": +"male", "female", or "other": .. configuration-block:: @@ -344,7 +344,7 @@ constraint, have several configuration options available. Suppose that the { /** * @Assert\Choice( - * choices = { "male", "female" }, + * choices = { "male", "female", "other" }, * message = "Choose a valid gender." * ) */ @@ -359,7 +359,7 @@ constraint, have several configuration options available. Suppose that the AppBundle\Entity\Author: properties: gender: - - Choice: { choices: [male, female], message: Choose a valid gender. } + - Choice: { choices: [male, female, other], message: Choose a valid gender. } # ... .. code-block:: xml @@ -376,6 +376,7 @@ constraint, have several configuration options available. Suppose that the @@ -404,7 +405,7 @@ constraint, have several configuration options available. Suppose that the // ... $metadata->addPropertyConstraint('gender', new Assert\Choice(array( - 'choices' => array('male', 'female'), + 'choices' => array('male', 'female', 'other'), 'message' => 'Choose a valid gender.', ))); } @@ -429,7 +430,7 @@ options can be specified in this way. class Author { /** - * @Assert\Choice({"male", "female"}) + * @Assert\Choice({"male", "female", "other"}) */ protected $gender; @@ -442,7 +443,7 @@ options can be specified in this way. AppBundle\Entity\Author: properties: gender: - - Choice: [male, female] + - Choice: [male, female,other] # ... .. code-block:: xml @@ -458,6 +459,7 @@ options can be specified in this way. male female + other @@ -483,7 +485,7 @@ options can be specified in this way. $metadata->addPropertyConstraint( 'gender', - new Assert\Choice(array('male', 'female')) + new Assert\Choice(array('male', 'female', 'other')) ); } } From 613ce4590c1be85dd2d8825408fd46fed3186734 Mon Sep 17 00:00:00 2001 From: Ben Huebscher Date: Tue, 5 May 2015 17:54:36 -0700 Subject: [PATCH 2/3] Update validation.rst --- book/validation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/validation.rst b/book/validation.rst index a9dc819f7f8..dbd2707d1c6 100644 --- a/book/validation.rst +++ b/book/validation.rst @@ -443,7 +443,7 @@ options can be specified in this way. AppBundle\Entity\Author: properties: gender: - - Choice: [male, female,other] + - Choice: [male, female, other] # ... .. code-block:: xml From 55f4115a511bef2efad6b6254dbb74d266130e86 Mon Sep 17 00:00:00 2001 From: Ben Huebscher Date: Thu, 7 May 2015 00:23:31 -0700 Subject: [PATCH 3/3] Remove Serial Comma --- book/validation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/validation.rst b/book/validation.rst index dbd2707d1c6..db983c6428e 100644 --- a/book/validation.rst +++ b/book/validation.rst @@ -329,7 +329,7 @@ Some constraints, like :doc:`NotBlank `, are simple whereas others, like the :doc:`Choice ` constraint, have several configuration options available. Suppose that the ``Author`` class has another property called ``gender`` that can be set to either -"male", "female", or "other": +"male", "female" or "other": .. configuration-block::