website logo
Thrive Themes
Navigate through spaces
Thrive Themes
⌘K
General
⚙️Thrive Themes Action Hooks & Custom Functions
⚙️How Can You Extend Thrive Themes Capabilities as a Developer
⚙️How to Integrate Your Thrive Themes Site to a Third Party Autoresponder
Thrive Architect
⚙️How to Develop Custom Rules For the Conditional Display Option
Thrive Automator
Untitled doc
⚙️Thrive Automator for Developers - Extending Automations' Capabilities
⚙️What Type of Data Do Thrive Automator Triggers and Actions Use?
⚙️Creating a New Start Trigger
⚙️Creating a New Filter in Thrive Automator
⚙️Creating a New Action in Thrive Automator
⚙️Creating Data Fields
⚙️Creating Trigger Fields
⚙️Creating Action Fields
⚙️Creating Apps
⚙️Creating Data Objects
Docs powered by archbee 
16min

Creating Trigger Fields

About trigger fields

Trigger Fields are the fields used for setting up an action in the admin user interface.

Creating your first trigger field

In order to create your own Trigger_Field you need to extend Thrive\Automator\Items\Trigger_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.
PHP
|
<?php
public static function get_id(): string { 
    return 'request_headers_toggle'; 
}

  • abstract public static function get_name(): string - the name of the Trigger_Field.
PHP
|
<?php
public static function get_name(): string { 
    return 'Headers'; 
}

  • abstract public static function get_description(): string - short description of the Trigger_Field that will be displayed in the tooltip
PHP
|
<?php
public static function get_description(): string {
return 'Whether you want custom headers';
}

  • abstract public static function get_placeholder(): string - input placeholder to be displayed in the admin UI.

PHP
|
<?php
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
PHP
|
<?php
/**
@see Utils::FIELD_TYPE_TEXT
@see Utils::FIELD_TYPE_TAGS
@see Utils::FIELD_TYPE_SELECT
@see Utils::FIELD_TYPE_CHECKBOX
@see Utils::FIELD_TYPE_AUTOCOMPLETE
@see Utils::FIELD_TYPE_DOUBLE_DROPDOWN
@see Utils::FIELD_TYPE_BUTTON
@see Utils::FIELD_TYPE_KEY_PAIR
*/
public static function get_type(): string {
return Trigger_Field::FIELD_TYPE_RADIO;
}


Other methods

  • abstract public static function get_validators(): array - return an array of validations that should be done on the field.
PHP
|
<?php
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.
PHP
|
<?php
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 from Data_Field as value for the current Trigger_Field
PHP
|
<?php
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.
PHP
|
<?php
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 Trigger_Field. $trigger_id - the current trigger where the field is displayed, useful when a single field is used in multiple triggers(e.g products list) $trigger_data - the current state of the trigger.
  • Can be used to filter the values based on other properties set for the current trigger
PHP
|
<?php
public static function get_options_callback( $trigger_id, $trigger_data ): array { 
    return [
            'none' => [
                       'id' => 'none', 
                       'label' => 'None', 
            ], 
            'custom' => [ 
                        'id' => 'custom', 
                        'label' => 'Custom', 
            ], 
     ]; 
}


Registering the trigger field

In order to register this Trigger_Field so it can appear in the admin area, we should use the thrive_automator_register_trigger_field function which receives as the only parameter, the class name.

Updated 03 Mar 2023
Did this page help you?
Yes
No
UP NEXT
Creating Action Fields
Docs powered by archbee 
TABLE OF CONTENTS
About trigger fields
Creating your first trigger field
Other methods
Registering the trigger field