-
Notifications
You must be signed in to change notification settings - Fork 7
The UI object provides a means of adding human readable labels and configuration options to the admin UI. Workflows can be hardcoded or they can be created from the Event and Destination building blocks.
A UI can be as simple as a single label or it can include a description and form fields.
Note the UI object is agnostic about where its data is stored. Getting and setting data should be handled manually for any hardcoded workflows. Workflows created via the admin UI automatically use the workflow post's metadata for storage and retrieval.
Creates and returns a UI object instance. These cannot be accessed directly but only via the variable they are assigned to or the Event or Destination object they are attached to.
The $name is the primary label shown in the admin UI.
$ui = UI::register( __( 'Custom event' ) );Set an extended description for the UI. This might be some instructions or additional information and context for users.
A UI can describe form fields that allow for adding custom configuration data. This means a single Destination or Event object can be used multiple times with different effects.
-
$nameis the storage key or id of the field, used as anameattribute on a form field. -
$labelis the human readable label for the form field -
$typeis the field type. The following types are supported by default:- text
- number
- url
- checkbox
- select
- textarea
-
$paramsis a collection of additional data used to create the field-
description: An optional string with additional help text - For "select" fields only:
-
options: an array of arrays withlabelandvaluekeys, eg.[ [ 'label' => 'One', 'value' => 1 ] ] -
multi: boolean, if true multiple items can be selected -
endpoint: array, this is a dynamic alternative tooptionswith the following keys:-
url: a REST API endpoint to retrieve options from. Must return an array. -
labelKey: The property to use for the dropdown labels, default is 'name' -
valueKey: The property to use for the dropdown values, default is 'ID'
-
-
-
Set the data for a UI, this is used as a lookup for the field values where the array keys match the $name for an added field.
Returns the data array for a UI object.
Retrieve a specific key's value from the UI data supplied in set_data().
Returns the UI's name property.
Returns the UI's description property.
Returns an array describing the UI object in the following shape:
- name
- description
- fields
- data
If you need a custom field type handler in the UI they can be added via JavaScript by extending the HM.Workflows.Fields global object.
New fields should extend the HM.Workflows.Fields.base React component class. You can find examples of the extended base field in /admin/src/Fields.