Use asModelFailure
and asModelSuccess
in v4
#85
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.
This PR changes the return values of failure and success responses to use Craft’s
asModelFailure
andasModelSuccess
controller methods. This helps standardise response structures and brings them in-line with how things have been done since Craft 4.This introduces a breaking change for the return values of JSON responses (https://github.com/craftcms/guest-entries/blob/main/README.md#submitting-via-ajax), therefore it should be considered it for version 4 (with Craft 5 compatibility).
I’m specifically requesting this change to make it easier for Sprig v3 to handle responses from the
SaveController
, which otherwise have to be handled individually, due to this inconsistency:https://github.com/putyourlightson/craft-sprig-core/blob/f7b60d416d935a4dd089a4b43d682087a79b991a/src/controllers/ComponentsController.php#L106-L108