-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
InlineValidator now binds $method to $model in 2.0.36 #18175
Comments
Inline validation methods are being bound to the model (the line item) in Yii 2.0.36, which can break validation rules defined by purchasable via getLineItemRules(), such as variant line item rules.
Inline validation methods are being bound to the model (the line item) in Yii 2.0.36, which can break validation rules defined by purchasable via getLineItemRules(), such as variant line item rules. Fixes #6372
I was able to work around this by wrapping inline validators’ closures in another closure (craftcms/cms@9f4105c), but the change should still at least be documented in the upgrade guide. |
This reverts commit 93b8016.
I used inline validators and js validation, that is broken with 2.0.36. In the class "yii\validators\InlineValidator" the method "clientValidateAttribute" has a bug. The line: |
@cs-crewsAndCaptains Probably worth posting that as a separate issue since it’s more of a direct bug as opposed to a gap in the documentation. |
@brandonkelly okay, if have add: #18204 |
As of b642a38, InlineValidator is now binding closures to the model being validated:
yii2/framework/validators/InlineValidator.php
Lines 76 to 78 in 700ac02
This is a change in behavior from prior versions which was not mentioned in the upgrade notes. It can lead to PHP errors from validation methods that were registered from a different class.
For example, Craft allows event-based rule registration with an
EVENT_DEFINE_RULES
event incraft\base\Model::rules()
:https://github.com/craftcms/cms/blob/68d7e40efc7630fc319a27e0536426028d7baa50/src/base/Model.php#L78-L89
So now if an inline validation rule is added via that event, like this:
A PHP error will occur, since
$this
within the callable is no longer a reference to the same class that the event handler was registered in; it will be the Entry object.What steps will reproduce the problem?
rules()
method.$this
to be the rule was originally defined in.What is the expected result?
$this
references the class the rule was defined in.What do you get instead?
$this
references the model’s class.Additional info
The text was updated successfully, but these errors were encountered: