[9.x] Allow specifiying custom messages for Rule objects#41145
Merged
taylorotwell merged 1 commit intoFeb 21, 2022
Merged
Conversation
Contributor
Author
|
I'm going to add some more tests to this:
|
Contributor
|
Love it! Had that recently with the new |
Member
|
Thanks! |
Member
|
@ryangjchandler can you make a PR to the docs? |
Contributor
Author
|
@taylorotwell Yeah, I can do that tomorrow if that's okay? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Closurerule and using$failAlso 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
$messagesarray.In this scenario, the custom messages provided to
$messageswould be used when the rule fails instead of the default message.