Skip to content

Latest commit

 

History

History
259 lines (214 loc) · 8.52 KB

form-field-support.md

File metadata and controls

259 lines (214 loc) · 8.52 KB

Gravity Forms Field Support

Gravity Forms is known for it's robust ecosystem of extenions. We aim to make it easy to support such customization, but there are limitations to what we can support out of the box.

By default, WPGraphQL for Gravity Forms adds basic query support for all Form fields recognized by Gravity Forms - including custom ones.

These types inherit the FormField interface.

Note: As of v0.10.0, Experimental fields are hidden by default and must be enabled. To track implementation status of experimental fields, please review this github issue

Form Field properties (GraphQL fields)

GraphQL fields are automatically registered to the type, based on the editor settings returned from GF_Field::get_form_editor_field_settings() .

Below is a list of supported editor settings:

  • add_icon_url_setting
  • address_setting
  • admin_label_setting
  • autocomplete_setting
  • background_color_setting
  • base_price_setting
  • border_color_setting
  • border_style_setting
  • border_width_setting
  • box_width_setting
  • calculation_setting
  • captcha_badge_setting
  • catcha_bg_setting
  • catcha_fg_setting
  • catcha_language_setting
  • catcha_size_setting
  • catcha_theme_setting
  • catcha_type_setting
  • chained_choices_setting
  • chained_selects_alignment_setting
  • chained_selects_hide_inactive_setting
  • checkbox_label_setting
  • choices_setting
  • columns_setting
  • conditional_logic_field_setting
  • conditional_logic_page_setting
  • content_setting
  • copy_values_option
  • credit_card_setting
  • css_class_setting
  • date_format_setting
  • date_input_type_setting
  • default_value_setting
  • default_value_textarea_setting
  • delete_icon_url_setting
  • description_setting
  • disable_margins_setting
  • disable_quantity_setting
  • duplicate_setting
  • email_confirm_setting
  • enable_enhanced_ui_setting
  • error_message_setting
  • file_extensions_setting
  • file_size_setting
  • force_ssl_field_setting
  • gquiz-setting-choices
  • gquiz-setting-randomize-quiz-choices
  • gquiz-setting-show-answer-explanation
  • input_mask_setting
  • label_placement_setting
  • label_setting
  • maxlen_setting
  • maxrows_setting
  • multiple_files_setting
  • name_setting
  • next_button_setting
  • number_format_setting
  • other_choice_setting
  • password_field_setting
  • password_setting
  • password_strength_setting
  • password_visibility_setting
  • pen_color_setting
  • phone_format_setting
  • placeholder_setting
  • placeholder_textarea_setting
  • post_category_checkbox_setting
  • post_category_initial_item_setting
  • post_custom_field_setting
  • post_image_featured_image
  • post_image_setting
  • prepopulate_field_setting
  • previous_button_setting
  • product_field_setting
  • range_setting
  • rich_text_editor_setting
  • rules_setting
  • select_all_choices_setting
  • size_setting
  • single_product_inputs_setting
  • sub_label_placement_setting
  • time_format_setting

Each setting is registered as a GraphQL Interface. Form fields that implement the above settings will have the GraphQL Interfaces and corresponding fields automatically registered to the type.

Custom field settings can be registered with the graphql_gf_form_field_setting_fields filter.

Form Field entry values

All Form fields have access to the value GraphQL field, which provides a string representation of the Form field's entry value, generated from GF_Field::get_value_export() .

Additionally, currently-supported Form Fields use type-specific value GraphQL fields.

Form Field input types

By default, complex Gravity Forms form fields inherit the GraphQL fields set by their GF_Field::$inputType .

Some Gravity Forms form fields (for example, the Quiz Field or Custom Post Field) can be resolved dynamically to multiple types (for example, a Checkbox or Radio ).

For Gravity Forms core, these form fields are automatically registered as GraphQL interfaces, with each possible input type as GraphQL object that implements the interface.

For an example of the PostCategory field:

gfEntries{
  formFields {
    nodes {
      databaseId
      inputType
      ... on GfFieldWithPostCategoryCheckboxSetting { # the Form Field Setting Interface
        hasAllCategories
      }
      ... on GfFieldWithEnhancedUISetting {
        hasEnhancedUI
      }
      ... on PostCategoryCheckboxField {
        checkboxValues {
          id
          value
        }
      }
      # works the same as this:
      ... on PostCategoryField { # the complex Form Field inherited interface.
        hasAllCategories
        ... on PostCategoryCheckboxField {
          checkboxValues {
            id
            value
          }
        }
      }
      # works the same as this:
      ... on PostCategorySelectField {
        hasEnhancedUI
        value
        hasAllCategories
        checkboxValues {
          id
          value
        }
      }
    }
  }
}

Developers wishing to support a custom Gravity Forms field that can resolve into multiple input types can make use of the graphql_gf_form_field_child_types filter.

Mutation Support

Currently, only certain Form fields are supported by GraphQL mutations and can be used to submit entries and draft entries. Form fields without an explicitly registered FormFieldValuesInput are given the default value input, however most custom Gravity Forms fields will require replacing that with a different FieldValueInput instance

Supported , Experimental , and Unsupported fields

At this stage of development, we category Gravity Forms fields into three types.

Supported fields

These core (and a few first-party extension) Form fields are explicitly supported by the plugin. Their type-specific properties are registered in WPGraphQL, and they are extensively tested.

Currently supported form fields:

  • AddressField
  • CaptchaField
  • ChainedSelectField
  • CheckboxField
  • ConsentField
  • DateField
  • EmailField
  • FileUploadField
  • HiddenField
  • HtmlField
  • ListField
  • MultiSelectField
  • NameField
  • NumberField
  • OptionField
  • PageField
  • PhoneField
  • PostCategoryField
  • PostContentField
  • PostExcerptField
  • PostImageField
  • PostTagsField
  • PostTitleField
  • PriceField
  • ProductField
  • QuantityField
  • QuizField
  • RadioField
  • SectionField
  • SelectField
  • ShippingField
  • SignatureField
  • TextAreaField
  • TextField
  • TimeField
  • TotalField
  • WebsiteField

Experimental fields

These Gravity Forms core-only fields are not yet explicitly supported by the plugin. The only properties they have are those registered by the supported field settings and the string-formatted entry value and they are untested. Further, they are not supported by Form submissions.

These forms are hidden by default:

  • CreditCardField

To enable these plugins, you can define the WPGRAPHQL_GF_EXPERIMENTAL_FIELDS constant to true in wp-config.php[https://wordpress.org/support/article/editing-wp-config-php/].

// wp-config.php
define( `WPGRAPHQL_GF_EXPERIMENTAL_FIELDS`, true );

You can also use the graphql_gf_ignored_field_types filter to add support on a field-by-field basis.

When a production-level version of this plugin is released, it is expected that all core Gravity Forms fields will be supported.

Unsupported Fields

These Form fields - either custom or from extensions - are given basic query support out of the box, depending on their use use of supported field settings, and support for additional GraphQL fields, input types, and submit/update mutations must be added manually.

Enabling/Disabling Field Support

You can manually enable/disable support for individual Gravity Forms using the graphql_gf_ignored_field_types filter.

add_filter(
  'graphql_gf_ignored_field_types', 
  function( array $ignored_fields ) : array {

    // Disable the 'MultiSelect' field.
    $ignored_fields[] = 'multiselect';

    // Enable the repeater field:
    $ignored_fields = array_diff( $ignored_fields, ['repeater'] );

    return $ignored_fields;

  }
);