-
Notifications
You must be signed in to change notification settings - Fork 2
Thrive Automator Action Fields
Vlad Matei edited this page Apr 26, 2023
·
7 revisions
Action Fields are the fields used for setting up an action in the admin UI.
In order to create your own Action_Field you need to extend Thrive\Automator\Items\Action_Field and implement the required basic methods.
-
abstract public static function get_id(): string- should return a unique identifier that will be used as a key in arrays. To avoid conflicts or overwrites we suggest using a prefix.
public static function get_id(): string {
return 'wp/user-role';
}-
abstract public static function get_name(): string- the name of the action field.
public static function get_name(): string {
return 'User role';
}-
abstract public static function get_description(): string- short description of the action field that will be displayed in the tooltip.
public static function get_description(): string {
return 'Create a new wordpress user';
}-
abstract public static function get_placeholder(): string- input placeholder to be displayed in the admin UI.
public static function get_placeholder(): string {
return 'user role';
}-
abstract public static function get_type(): string- type of input field, required to render in the admin UI.
/**
* @see Utils::FIELD_TYPE_TEXT
* @see Utils::FIELD_TYPE_TAGS
* @see Utils::FIELD_TYPE_SELECT
* @see Utils::FIELD_TYPE_SELECT_TOGGLE
* @see Utils::FIELD_TYPE_CHECKBOX
* @see Utils::FIELD_TYPE_RADIO
* @see Utils::FIELD_TYPE_AUTOCOMPLETE
* @see Utils::FIELD_TYPE_DOUBLE_DROPDOWN
* @see Utils::FIELD_TYPE_BUTTON
* @see Utils::FIELD_TYPE_MAPPING_PAIR
* @see Utils::FIELD_TYPE_KEY_PAIR
* @see Utils::FIELD_TYPE_TEXTAREA
* @see Utils::FIELD_TYPE_BUTTON
*/
public static function get_type(): string {
return Utils::FIELD_TYPE_SELECT;
}-
abstract public static function get_validators(): array- return an array of validations that should be done on the field.
public static function get_validators(): array {
return [ static::REQUIRED_VALIDATION ];
}-
abstract public static function is_ajax_field(): bool- check if the field values are retrieved normally or with an ajax request.
public static function is_ajax_field(): bool {
return true;
}-
public static function allow_dynamic_data(): bool- Whether users should be allowed to add dynamic data fromData_Fieldas value for the currentAction_Field.
public static function allow_dynamic_data(): bool {
return false;
}-
public static function get_default_value(): string- can be used to set default values for a field e.g select field.
public static function get_default_value(): string{
return 'first_key';
}-
abstract public static function get_options_callback(): array- return an array of id/label arrays representing the option values for the action field.$action_id- the current action where the field is displayed, useful when a single field is used in multiple actions(e.g products list)$action_data- current state of the action. Can be used to filter the values based on other properties set for the current action
public static function get_options_callback( $action_id, $action_data ): array {
return [
[
'id' => 'subscriber',
'label' => 'Subscriber',
],
[
'id' => 'author',
'label' => 'Author',
],
];
}In order to register this Action_Field so it can appear in the admin area, we should use the thrive_automator_register_action_field function which receives as the only parameter, the class name.