Schema Form schema fields

In addition to standard fields in Drupal schemas like type and label, the module allows you to add extra fields to the schema to provide metadata for the form building process.

Here is a list of available fields:

    # And more formats to support schemas created for other similar modules
    # without changes:
    my_another_field:
      type: string
      label: My Another Field # Label from Drupal Core, priority: 4.
      title: My Another Field Title # Module: auto_config_form, priority: 3.
      description: My another field description # Module: auto_config_form, priority: 3.
      '#title': My Another Field Title # Module: schema_based_config_forms, priority: 2.
      '#description': My another field description # Module: schema_based_config_forms, priority: 2.
      '#field_prefix': <div>
      '#field_suffix': </div>
      '#schema_form_hide': true
      '#schema_form_plugin': my_custom_plugin
      third_party_settings:
        schema_form:
          element:
            '#title': My Another Field Title # The most relevant to this module, priority: 1.
            '#description': My another field description # The most relevant to this module, priority: 1.

If you use only this module to build forms, we recommend using the Schema Form Design feature to customize the forms, instead of storing the form design directly in the schema. This will keep the schema data clean and compact.

However, the description key is better kept together with the schema, because it is directly related to the data stored in the schema. Here is an appeal to add it to the Drupal schema allowed fields.

If you still want to keep everything in the schema, use the third_party_settings section to declare the form-related data, to keep it explicit and separated from the standard schema fields in Drupal.

Examples

Here is a simple design metadata example:

my_module.my_feedback_form:
  type: schema_form
  label: Send us your feedback
  mapping:
    ...
    first_name:
      type: string
      label: First name
      description: We'll be glad to know your name.

In this example, we added a description. The 'description' field is not part of the Drupal schema, but you are not restricted from using additional fields in Drupal schema YAML files. The module uses this trick to simplify customizing the form. If you don't want to use this approach, you can always return to the classic way by customizing the pre-generated form array using PHP.

To avoid conflicts with other modules, the module supports the third_party_settings property, which takes priority over other values:

my_module.my_form:
  type: mapping
  mapping:
    ...
    my_field:
      type: string
      label: My Field
      third_party_settings:
        schema_form:
          element:
            '#title': My Field Title
            '#description': My field description
            '#default_value': foo
            '#attributes':
              class:
                - my-field
            # And all other custom values for the form array element.

For convenience, it also supports a simpler declaration of common properties (title and description), like this:

my_module.my_form:
  type: mapping
  mapping:
    ...
    my_field:
      type: string
      label: My Field
      title: My Field Title # Custom title to overwrite the schema item label for the form element. If filled, but description is empty, the label is used as description.
      description: My field description # The field description text.

See more examples in the submodule directory tests/modules/schema_form_test.

Actually, the Drupal schema JSON format doesn't support non-standard properties or even third_party_settings, but they work without any problems because the check is not strict. However, there is no way to attach additional metadata to the schema items, so please vote on this issue #3522197 to add support for this.

Separate design from schema

If you don't want to clog up the schema with the design metadata, use the Schema Form Design entities instead.