- 108 views
Add the following code to your_module.module file
Using the hook_rules_action_info() you can add your own Action which you will be able to select from inside Rules UI.
/**
* Implementation of hook_rules_action_info().
*/
function devlubo_rules_action_info() {
return array(
'my_custom_action' => array(
'label' => t('DevLubo - Custom Action'),
'arguments' => array(
'node_id' => array('type' => 'integer', 'label' => t('Node ID')),
),
'provides' => array(
'devlubo_custom_variable_output' => array(
'type' => 'decimal',
'label' => t('This will provide custom variable output'),
),
),
'base' => 'devlubo_rules_alter_the_custom_variable',
'module' => 'devlubo'
),
);
}
Explaining the code in line by line fashion you can see the following:
Defining your custom action:
'my_custom_action' => array(
How will your action be listed in a select list in Rules UI:
'label' => t('DevLubo - Custom Action'),
Which arguments does your custom action take (in this example Node ID)
'arguments' => array(
'node_id' => array('type' => 'integer', 'label' => t('Node ID')),
),
Which variables will the custom action provide to work with later in Rule execution
'provides' => array(
'devlubo_custom_variable_output' => array(
'type' => 'decimal',
'label' => t('This will provide custom variable output'),
),
),
Custom function to work with the variable
'base' => 'devlubo_rules_alter_the_custom_variable',
Working inside the custom variable function
As you can see, we have defined in hook_rules_action_info() which function will handle the variable. So we can as an example set the value to custom number as a return value.
/**
* Action: Set a variable to custom value.
*/
function devlubo_custom_variable_output($args, $element) {
return array('devlubo_custom_variable_output' => "500");
}