Repository navigation
[6.x] Forms 2: Expose form sections, pages and access restrictions in the REST & GraphQL APIs - #15349
Merged
Merged
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
…pages # Conflicts: # src/Forms/Form.php # tests/Feature/GraphQL/FormTest.php
…on message The restriction message depends on who is logged in, which an API request can't know. Expose the configured closed_message and require_login_message so headless frontends can decide what to show from status and require_login. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Untitled pages were returned with the control panel's "Page X of Y" placeholder. Return null instead, and cover the single-page shape. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 with anidofmain.A page's
displayis the title configured in the form builder, ornullwhen it doesn't have one. The Control Panel's "Page 1 of 2" placeholder isn't returned, so frontends can decide whether to render a heading.Sectioned fieldset imports keep their sections (using
Tab::expandedSections()from #15694), rather than being merged into the section they were imported into.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_login,closed_messageandrequire_login_messagealongside the existingstatus, so headless frontends can tell whether a form is currently accepting submissions and what to show when it isn't.The messages are the ones configured on the form (or the default messages when they're left blank), and they're always returned. It's up to the frontend to decide which one applies:
closed_messagewhenstatusisn'topen, andrequire_login_messagewhenrequire_loginis true and its visitor isn't logged in. The API can't know who is visiting a headless frontend, which is why the template-onlyrestriction_messageisn't exposed.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": null, "instructions": null, "sections": [...] } ], "status": "open", "require_login": false, "require_login_message": "You must be logged in to submit this form.", "closed_message": "This form is no longer accepting submissions.", "api_url": "http://example.com/api/forms/contact" } }GraphQL
{ form(handle: "contact") { status require_login require_login_message closed_message pages { id display instructions sections { display instructions fields { handle display } } } } }Closes statamic/ideas#1320