Drupal 7 Creating New Actions for Rules
Code dump for my personal reference. I'll build on this topic as I continue to learn.
Inside of modulename_rules.inc
function modulename_rules_action_info() {
$defaults = array(
'parameter' => array(
'account' => array(
'type' => 'user',
'label' => t('User'),
// Saves any changes made to the user object,
// or changes made in modulename_action_user_test().
'save' => TRUE,
),
),
'group' => t('User'),
// Defined in user.rules.inc within the rules module.
'access callback' => 'modulename_user_integration_access',
);
$actions['user_test'] = $defaults + array(
'label' => t('user test'),
'base' => 'rules_action_user_test',
);
return $actions;
}
/**
* Action: Create a message to see if it works.
*/
function modulename_action_user_test($account) {
drupal_set_message('New action works!');
// We can make changes to $account
// $account->status= 1;
}
This adds a new action that you can manually add to an existing rule.
Leave a comment