Field API
While RJSF's main purpose is to be programmatically added to forms via Form API the module also provides a field type and widget to allow RJSF forms to be added to fieldable entities. To add an RJSF form as a field
- Navigate to your content entity's
Manage Fields
page - Click
Add field
- Select
RJSF Data
as the field type, fill in a field name and create the field - Fill in the schema, uiSchema, and renderPreprocess settings with valid json strings. See Schema Structure for available schema properties and what they do.
- Enable Serverside and Live validation as needed
- It is highly recommended to leave Serverside validation enabled whenever using a schema that references Drupal data.
- You now have an RJSF form on a content entity.
Accessing the data
When a form is submitted the RJSF data is available as json string under the values
attribute of the field. One way to access this is
Json::decode($entity->{field_name}->value));
Displaying RJSF data
RJSF does not provide a functional FieldFormatter. The data collected can be used
- By defining a custom field template in your theme. @TODO Add full example for how to override the default RJSF field formatter.
- In entity create/update/delete events as contextual information
- In entity preprocess functions to as contextual information
- Directly rendered in the entity's twig template.