-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Validator] Explained how to use array constant in annotation #10810
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
Conversation
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.
Thank you very much for this contribution!
Hi @HeahDude i've wondered if this would need a |
a810dae
to
83a2304
Compare
reference/constraints/Choice.rst
Outdated
Supplying the Choices from an Array Constant | ||
-------------------------------------------- | ||
|
||
You can also directly provide an array constant to the ``choices`` option in the annotation:: |
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.
- array constant
+ constant containing an array
sounds a bit better
reference/constraints/Choice.rst
Outdated
|
||
class Author | ||
{ | ||
const GENRES = ['fiction', 'non-fiction']; |
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.
I would prefer sth like action
and comedy
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.
yep, i agree, but i've chosen these one for the coherence with the example above
would you mind that i change the other example as well ?
reference/constraints/Choice.rst
Outdated
|
||
.. note:: | ||
|
||
If the constant is stored in a different class, you can pass the fully qualified class name |
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.
s/stored/defined/
reference/constraints/Choice.rst
Outdated
.. note:: | ||
|
||
If the constant is stored in a different class, you can pass the fully qualified class name | ||
of the class or import this class by adding it to the "use" list. |
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 line is not needed
Thank you for your contribution 👍 |
83a2304
to
3f0ad71
Compare
reference/constraints/Choice.rst
Outdated
|
||
.. warning:: | ||
|
||
Notice that the constant in the option is used without quotes. |
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.
Notice that the constant in the option is used without quotes. | |
The constant in the option is used without quotes. |
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.
👍
3f0ad71
to
9b23462
Compare
reference/constraints/Choice.rst
Outdated
@@ -279,6 +279,35 @@ you can pass the class name and the method as an array. | |||
} | |||
} | |||
|
|||
Supplying the Choices from an Array Constant |
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.
array constant in lower case is better i think, wdyt?
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.
yes you're right
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.
actually i've wrote like this, to be consistent with the title above which is Supplying the Choices with a Callback Function
reference/constraints/Choice.rst
Outdated
|
||
.. warning:: | ||
|
||
The constant in the option is used without quotes. |
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.
what about both inside note instead of warning? warning can be misunderstood
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.
do you mean in the same note or two different notes ?
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.
do you mean both inside the same note ?
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.
the same i think
I wonder if it would not be easier to expand the code example that we have in the "Basic usage" section to also contain choices coming from a constant and adding an inline comment there. |
hi @OskarStark sorry, i've forgotten this one, i was thinking it was merged. here is some update. |
Nicolas, thanks for this contribution ... and sorry for the late merge! |
…ation (nikophil) This PR was squashed before being merged into the 3.4 branch (closes #10810). Discussion ---------- [Validator] Explained how to use array constant in annotation Hi, few days ago i tried to add a new feature to the `choice` validator constraint, by adding a new `choicesFromConstant` option. symfony/symfony#29658 But then, i realized this was already supported. I think this should be documented, as i think a lot of people don't know this feature. thanks. Commits ------- 7774aab [Validator] Explained how to use array constant in annotation
Hi,
few days ago i tried to add a new feature to the
choice
validator constraint, by adding a newchoicesFromConstant
option.symfony/symfony#29658
But then, i realized this was already supported.
I think this should be documented, as i think a lot of people don't know this feature.
thanks.