Repository navigation
Add support for Forms 2 - #126
Open
duncanmcclean wants to merge 7 commits into
Open
duncanmcclean wants to merge 7 commits into
duncanmcclean wants to merge 7 commits into
Conversation
forms 2 hasn't shipped yet, so this points at the `forms-2` branch of statamic/cms for now, aliased as `6.31.0` so dependency constraints keep resolving. also sorts the `require` block alphabetically. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ATXH2uZVrsXqYrGqUoKhQA
forms no longer have dedicated blueprint files, so blueprint deletion in the tests needs to be null-safe. the `Statamic` facade alias is also registered for the test app, as testbench doesn't register it and the toggle view relies on it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ATXH2uZVrsXqYrGqUoKhQA
when a fieldtype has no model binding of its own, fall back to the binding of its closest parent class. this lets subclassed fieldtypes, like forms 2's `YesNo` extending `Radio`, resolve without needing a binding of their own. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ATXH2uZVrsXqYrGqUoKhQA
adds models, config bindings, and default views for the fieldtypes introduced by forms 2: `date_picker`, `time_picker`, `star_rating`, `opinion_scale`, `ranking`, `image_choice`, `upload`, `group`, `heading`, `paragraph`, and `banner`. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ATXH2uZVrsXqYrGqUoKhQA
when the `SubmitForm` action exists, submissions are handled by statamic itself so spam protection, restrictions, file uploads, events, and emails behave exactly like a native form submission. validation errors are mapped back to their livewire error keys, and restricted forms surface their message as a form-level error. older statamic versions continue to use the addon's own submission flow. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ATXH2uZVrsXqYrGqUoKhQA
covers rendering and field model resolution of the new fieldtypes, persisting submissions, file uploads, restrictions, event isolation between forms submitted in the same request, and validation error mapping. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ATXH2uZVrsXqYrGqUoKhQA
Owner
|
Thanks, Duncan. Really appreciate this PR! |
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.
This pull request updates the addon to support the upcoming Forms 2 changes in Statamic Core, while staying compatible with current Statamic versions, so it shouldn't need a breaking release.
As this is quite a popular addon, I wanted to open a PR to give you a head start on supporting the new features.
What's changing in Core?
We're overhauling forms — forms get a dedicated form builder with a bunch of new form-specific fieldtypes (
star_rating,opinion_scale,ranking,image_choice,group, etc.), and submissions now run through a newSubmitFormaction which handles validation, spam, restrictions, file uploads, events and emails in one place.The new fieldtypes cause an error when rendering a form with this addon, hence this PR.
What's in this PR?
short_answercompiles totext. Some of the underlying fieldtypes are new classes extending existing ones, so field models now fall back to the binding of their closest parent class, e.g.yes_noresolves to theRadiomodel.SubmitFormaction when it exists, so they behave exactly like native Statamic submissions. On older Statamic versions, the existing submission flow is used instead — you'll probably want to drop the old flow in your next major version.TestCase: blueprint deletion is null-safe now, since forms no longer have dedicated blueprint files, and theStatamicfacade alias is registered, since the toggle view uses it and the new tests render every fieldtype.I've deliberately kept this to the minimum needed to make everything work — no new features, no unrelated refactoring. Obviously feel free to change whatever you like, and DM me if you have any questions!
Testing it out
You can test this against Forms 2 using the
forms-2-previewbranch ofstatamic/cms, which contains the built assets — no need to compile anything:Forms 2 should be considered alpha right now — things are highly likely to change, so only use it locally for testing.