-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Validator Documentation for Collection constraint Required/Optional options #2432
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
Validator Documentation for Collection constraint Required/Optional options #2432
Conversation
and Optional classes.
for fields within a Collection. | ||
|
||
Required and Optional Field Constraints | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
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 heading line should be as long as the heading title
Note: YML and XML examples for configuration are not included. Worked with weaverryan to try to come up with a working version in YML without success. This gist contains the YML configuration I tried: The issue was that the constraint for the field needed to be parsed into an instance of Required or Optional and instead it was always parsed into an array with a single instance of Required or Optional in it. Might be a YML limitation or just something wrong with the syntax I tried. |
|
||
Even without ``allowMissingFields`` set to true, you can now omit the ``alternate_email`` property complete from the profileData array, since | ||
it is ``Optional``. However, if the the ``personal_email`` field does not exist in the array there will be a | ||
constraint violation that the field is missing, since it is ``Required``. |
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.
some line breaking missing.
Fixed whitespace issues from your comments. |
* @Assert\Collection( | ||
* fields={ | ||
* "personal_email" = @Required({@Assert\NotBlank, @Assert\Email}), | ||
* "alternate_email" = @Optional({@Assert\Email}), |
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 prefer to have the 2 =
lined up with eachother.
Formatting changes per comments from @wouterj
Change 'example' to 'instance'.
} | ||
|
||
Even without ``allowMissingFields`` set to true, you can now omit the ``alternate_email`` property | ||
completely from the profileData array, since it is ``Optional``. However, if the the ``personal_email`` |
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.
completely from the ``profileData`` array [...]
Add variable indicators around profileData
Removed use statements for Required/Optional. Instead use Assert\Collection\Required.
you should add the YAML and XML mapping too |
@stof it seems like this is not possible with Yaml and Xml. Afishnamedsquish, Ryan and I have tried it but can't come with a solution. Even bernhard didn't know the format, see also: https://gist.github.com/afishnamedsquish/5277987 |
@wouterj This should be reported as a bug if YAML and XML don't support it. Can you open a ticket ? |
@stof, yes I will do |
…optional_required_docs Validator Documentation for Collection constraint Required/Optional options
Hey! This is a really nice entry - very clearly explained, nice work! I did tweak some minor language at sha: cf049ed, because iirc, Thanks! |
This works for me: Acme\AuthorBundle\Entity\Author:
properties:
profileData:
- Collection:
fields:
alternate_email:
constraints:
- Collection\Optional:
- Email: ~ Can someone confirm? |
negative for sf2.1 (didn't test it in other versions) |
This PR was submitted for the 2.1 branch but it was merged into the 2.2 branch instead (closes #7930). Discussion ---------- handle Optional and Required constraints from XML or YAML sources correc... ...tly | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #7575 | License | MIT | Doc PR | symfony/symfony-docs#2432 Commits ------- a93a23a handle Optional and Required constraints from XML or YAML sources correctly
Now that symfony/symfony#7930 is merged. Is any work left here? |
An example of YML configuration could be added to the docs |
And a xml example |
You're right, see #2841 for this. |
#999