Problem/Motivation
Part 2 of splitting #3595219: 3.0 Exploration. This issue covers form-level rendering correctness: conditional #states, multi-page (wizard) forms, and building a form for a source entity with query-string prepopulation. These are grouped because they all concern what a built form instance actually renders for a given context, rather than any single element type.
Problems addressed:
- Inverted
#statesconditions. Conditional logic such as "visible when X is empty" / "invisible when checked" is emitted with the wrong trigger or an empty value, so consumers rebuilding conditional visibility get incorrect behaviour. - States lost on multi-page (wizard) forms. When a webform is split into wizard pages, element
#statesare not resolved, so conditional logic disappears for any non-trivial form. - No source entity / prepopulation support. A built form often depends on a source entity and on values prepopulated from the query string (Webform's
?element=valueprepopulation). The module cannot build a form for a given source entity or apply query-string prepopulation, and the resulting cacheability (per-URL, per source entity) is not represented.
Proposed resolution
- Fix
#statesresolution so negated conditions (empty / unchecked / unfilled) emit the correct trigger and value, insrc/Plugin/GraphQL/DataProducer/WebformElementState.php(and its metadata wiring). - Resolve
#statesacross wizard pages so conditional logic survives multi-page forms. - Build the form for an optional source entity and apply Webform's query-string prepopulation, exposing the prepopulated default values and bubbling the correct cache metadata (URL / source-entity cache tags and contexts) into the response — building on the cacheability foundation in #3598935: Improve cacheability and rendering.
Remaining tasks
- Correct negated
#statestrigger/value handling inWebformElementState.php; cover withtests/src/Kernel/DataProducer/WebformElementStateTest.php. - Resolve states across wizard pages; cover with
tests/src/Kernel/Element/WizardPageStatesTest.php. - Pass the source entity into the form build and apply query-string prepopulation in
src/Plugin/GraphQL/DataProducer/WebformElements.php/WebformForm.phpand the schema wiring. - Tests:
WebformPrepopulateTest,WebformSourceEntityCacheMetadataTest,WebformSourceEntityTokensTest, plus theprepopulate.gql/source_entity_*.gqlquery fixtures.
API changes
Additive and correctness-only: conditional #states are now reported correctly (including negated conditions and on wizard forms), and a form can be built for a source entity with query-string prepopulation, with correct cache metadata. No fields are removed.
Release notes snippet
Conditional element logic (#states) is now resolved correctly, including negated conditions and on multi-page (wizard) forms. Forms can be built for a source entity and prepopulated from the query string, with correct cache metadata on the response.
Issue fork graphql_webform-3598964
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
pfrenssen