Skip to content

Instantly share code, notes, and snippets.

@miteshmap
Last active December 29, 2015 12:49
Show Gist options
  • Select an option

  • Save miteshmap/7673018 to your computer and use it in GitHub Desktop.

Select an option

Save miteshmap/7673018 to your computer and use it in GitHub Desktop.
Implements hook_rule_condition_info - add condition to rules.
<?php
/**
* Implements hook_rules_condition_info()
*/
function foo_rules_condition_info() {
return array(
'foo_check' => array(
'label' => t('Check foo condition'),
'parameter' => array(
'param' => array(
'type' => 'list<text>',
'label' => t('foo label'),
'options list' => 'callback_function_to_return_options',
'description' => t('The condition to check for.'),
'restriction' => 'input',
),
),
'base' => 'callback_function_to_validate',
'group' => t('System'),
),
);
}
/**
* Condition implementation: Check if param and condition is equal or not.
*/
function callback_function_to_validate($param) {
$current_value = get_current_value(); // get the current value to check against condition value.
return in_array($current_value, $param);
}
function callback_function_to_return_options() {
return array(1 => 'value1', 2 => 'value2', '3' => 'value3');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment