GraphQL Compose: Entity form modes
Security covered
Graphql ecosystem
This module makes entity form mode field definitions and structure available through GraphQL. This allows headless applications to retrieve and display form fields, including their settings and groups, and to even pre-fill forms with existing data.
Exposes entity form mode field definitions and structure via GraphQL for headless applications.
Requirements
- Drupal 10.1+
- PHP 8.1+
- GraphQL Compose
- GraphQL Compose Mutations
Schema Extension
Adds the entityFormMode field to the Query root type:
extend type Query {
entityFormMode(
entity_type: EntityType!
entity_bundle: String!
entity_id: String
operation: Operation
): EntityFormModeResponse
}
Response Type
type EntityFormModeResponse implements Response {
success: Boolean
errors: [Violation]
form: Json
form_mode_fields: Json
form_mode_field_groups: Json
}
Query Example
Retrieve form fields for a node bundle (create operation)
query GetNodeFormFields {
entityFormMode(
entity_type: NODE
entity_bundle: article
operation: CREATE
) {
success
errors {
message
}
form_mode_fields {
machine_name
type
required
weight
settings {
cardinality
type
}
widget {
#type
#title
#description
#required
}
existing_values
}
form_mode_field_groups {
machine_name
label
format_type
parent_field_group
children
weight
}
}
}
Retrieve form with pre-filled values (update operation)
query GetNodeFormFields {
entityFormMode(
entity_type: NODE
entity_bundle: article
entity_id: "123"
operation: UPDATE
) {
success
form_mode_fields {
machine_name
existing_values
}
}
}
Permission Handling
Access control uses graphql_compose_mutations.user_permissions service:
- Validates user permissions via
userCanDoActionOnEntityByType() - Administrators (uid=1 or 'administrator' role) bypass permission checks
- Returns validation violations if access is denied
Widget Properties Filter
To prevent JSON recursion, only these widget properties are returned:
-
#base_type,#date_date_format,#date_time_format,#date_timezone,#date_year_range -
#delta,#description,#description_display,#form_group,#id,#name -
#options,#placeholder,#required,#title,#title_display,#type