Skip to content

[Validator] feat(when constraint): add context variable #20314

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

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
4 changes: 3 additions & 1 deletion reference/constraints/When.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ validation of constraints won't be triggered.
To learn more about the expression language syntax, see
:doc:`/reference/formats/expression_language`.

Depending on how you use the constraint, you have access to 1 or 2 variables
Depending on how you use the constraint, you have access to 1 or 3 variables
in your expression:
Comment on lines +166 to 167
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Depending on how you use the constraint, you have access to 1 or 3 variables
in your expression:
Depending on how you use the constraint, you have access to different variables
in your expression:

To match with text in doc for Expression constraint, "to 1 or 3 variables" doesn't feel clear to me

Copy link
Contributor

Choose a reason for hiding this comment

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

What about « multiple internal variables »

Copy link
Member

Choose a reason for hiding this comment

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

Done while merging. Thanks.


``this``
The object being validated (e.g. an instance of Discount).
``value``
The value of the property being validated (only available when
the constraint is applied to a property).
``context``
This is the context that is used in validation
Comment on lines +174 to +175
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a versionadded directive for this new variable ?

Copy link
Member

Choose a reason for hiding this comment

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

We need to improve this description. Right now it's basically saying "context is the validation context" 😐

For example, in the Validation article (https://symfony.com/doc/current/validation.html) the word context is not even mentioned once. So, what's the "validation context"? Any article that we could link from here so readers can learn more? Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Done while merging too. Thanks.


The ``value`` variable can be used when you want to execute more complex
validation based on its value:
Expand Down
Loading