[9.x] Allow specifiying custom messages for Rule
objects
#41145
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There's not currently any simple way to specify a custom message when validating with a rule object.
Here are the current userland work-arounds and caveats:
Ensure custom rule uses translation strings for message
This would affect all uses of the message. Not very useful for changing the message in a single place.
Extending the rule object with a custom
message()
methodNot a very nice API. A lot of work for a simple thing.
Interacting with the rule object from a
Closure
rule and using$fail
Also not very nice. Requires knowledge of the Rule's dependencies, etc (think 3rd party packages).
With the changes in this PR, you can now provide a custom message to the
$messages
array.In this scenario, the custom messages provided to
$messages
would be used when the rule fails instead of the default message.