Skip to main content

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

  1. Navigate to your content entity's Manage Fields page
  2. Click Add field
  3. Select RJSF Data as the field type, fill in a field name and create the field
  4. Fill in the schema, uiSchema, and renderPreprocess settings with valid json strings. See Schema Structure for available schema properties and what they do.
  5. Enable Serverside and Live validation as needed
    1. It is highly recommended to leave Serverside validation enabled whenever using a schema that references Drupal data.
  6. 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.