-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] When Constraint only works with public class properties #49367
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
Comments
the Symfony ExpressionLanguage does not have the same magic than Twig for the |
I tried with This also fixes my problem, the only reason it was not working was a coding logic when initialize the form; Much appreciated; I was not very familiar with the Symfony ExpressionLanguage. |
I opened symfony/symfony-docs#17905 to update the documentation with a working example. I'm closing this issue here as there is no bug in Symfony itself. |
This PR was merged into the 6.2 branch. Discussion ---------- Fix the example for the When constraint When evaluating the expression, the ExpressionLanguage does not have access to private properties of the object, as it runs from its outside. And contrary to Twig, ExpressionLanguage does not have the magic `.` operator that tries to find a getter when it cannot use the property. See symfony/symfony#49367 for a support request caused by this bad example. Commits ------- 7ad1447 Fix the example for the When constraint
Symfony version(s) affected
6.2.2
Description
When trying to use the When constraint and it seems to be working only with public class properties; if the property is declared protected or private, it throws the error Cannot access protected property App\Model\ExampleModel::$mainProperty
How to reproduce
In a model class, let's say App\Model\ExampleModel::$mainProperty, we declare 2 properties, where property protected $secondaryProperty should depend on protected $mainProperty. Boit properties have public getters and setters.
Not working
Partially working - not throwing error anymore, but does not evaluate the conditional expression properly, meaning id does not throw the constraint validation message; form behaves like it does not have an error.
Working - only when the expression is set explicitly to TRUE; now, the constraint's message it is present when trying to submit the form
###Info - both properties have public getters and setters
Possible Solution
No response
Additional Context
Where $previousOnlinePaymentsAccepted is $mainProperty and $acquirer is $secondaryProperty
The text was updated successfully, but these errors were encountered: