From 7ad14476b3588b8c9190d83cb6e5b67042bd9877 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 14 Feb 2023 11:19:21 +0100 Subject: [PATCH] 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. --- reference/constraints/When.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reference/constraints/When.rst b/reference/constraints/When.rst index acd35cddcf5..ed855857b1d 100644 --- a/reference/constraints/When.rst +++ b/reference/constraints/When.rst @@ -69,7 +69,7 @@ One way to accomplish this is with the When constraint: { #[Assert\GreaterThan(0)] #[Assert\When( - expression: 'this.type == "percent"', + expression: 'this.getType() == "percent"', constraints: [ new Assert\LessThanOrEqual(100, message: 'The value should be between 1 and 100!') ], @@ -87,7 +87,7 @@ One way to accomplish this is with the When constraint: value: - GreaterThan: 0 - When: - expression: "this.type == 'percent'" + expression: "this.getType() == 'percent'" constraints: - LessThanOrEqual: value: 100 @@ -105,7 +105,7 @@ One way to accomplish this is with the When constraint: 0