[6.x] Forms 2: Expose form sections, pages and access restrictions in the REST & GraphQL APIs - #15349
Open
duncanmcclean wants to merge 2 commits into
Open
[6.x] Forms 2: Expose form sections, pages and access restrictions in the REST & GraphQL APIs#15349duncanmcclean wants to merge 2 commits into
duncanmcclean wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qe1g6yd25kh7oTxtWfzB95
… graphql apis Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qe1g6yd25kh7oTxtWfzB95
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 implements support for form
sectionsin the REST API, andpagesin both the REST and GraphQL APIs. The GraphQL API has hadsectionssince #11466 but the REST API never got them, and neither API exposed pages.sectionsreturns every section across all pages, so it's the easy way to render a single-page form with the same structure as the Control Panel.pagesreturns each page'sid,display,instructionsand itssections, for rendering multi-page forms. Single-page forms return a single page.This PR also fixes the GraphQL
sectionsfield only returning the first page's sections on multi-page forms.Access restrictions
This PR also exposes
require_loginandrestriction_messagealongside the existingstatus, so headless frontends can tell whether a form is currently accepting submissions and what to show when it isn't.restriction_messageonly covers the closed and limit reached cases. The login case is deliberately left out, since the API can't know who is visiting a headless frontend.require_loginis exposed as a plain boolean instead so the frontend can make that call itself.REST API
GET /api/forms/contact{ "data": { "handle": "contact", "title": "Contact", "fields": { "name": {...}, "email": {...} }, "sections": [ { "display": "Your Details", "instructions": null, "fields": { "name": {...}, "email": {...} } } ], "pages": [ { "id": "main", "display": "Page 1 of 1", "instructions": null, "sections": [...] } ], "status": "open", "require_login": false, "restriction_message": null, "api_url": "http://example.com/api/forms/contact" } }GraphQL
{ form(handle: "contact") { status require_login restriction_message pages { id display instructions sections { display instructions fields { handle display } } } } }Closes statamic/ideas#1320