I noticed this great module's actions were not appearing in Rules actions.
From what I read it should work with all standard actions_api actions but apparently not.
Anyway, I added the following to the node_convert.rules.inc file and it seems to work well.
/**
* Implements hook_rules_action_info().
* @ingroup rules
*/
function node_convert_rules_action_info() {
$actions = array();
$actions['node_convert_convert_nodes_using_template_rules_callback'] = array(
'label' => t('Convert a node'),
'group' => t('Node'),
'parameter' => array(
'template' => array(
'type' => 'text',
'label' => t('Select the Convert Template you wish to use.'),
'options list' => 'node_convert_templates_list',
),
'node' => array(
'type' => 'node',
'label' => t('Node to convert'),
),
),
);
return $actions;
}
/**
* Takes rules action parameters and passes them to the convert function.
*
* @param $template
* The template id to use for conversion.
* @param $node
* Full node object
* @return
* FALSE if conversion fails, this is return of convert function.
*/
function node_convert_convert_nodes_using_template_rules_callback($template, $node){
return node_convert_convert_nodes_using_template(array($node->nid), $template);
}
/**
* Helper - Gets a list of templates and id's.
*
* @return
* A assocaited array of template id's and names.
*/
function node_convert_templates_list() {
$result = db_query("SELECT * FROM {node_convert_templates}");
$templates = array(0 => 'none');
foreach ($result as $row) {
$access = node_convert_check_template_permission_user(array('template_id' => $row->nctid));
if ($access == TRUE) {
$templates[$row->nctid] = $row->name;
}
}
return $templates;
}
now ... you can create a rules trigger, condition and action set and choose which template to apply.
I havent explored it very much, e.g I dont know what happens if you dont choose a template as all this does is pass some variable back to the convert function.
I'm using this with Taxonomy so that whan some one changes the a term it changes the node type, it works well for me.
I can provide a patch if needed.
Comments
Comment #1
pbrough commentedIs there any progress on this? Do you have a patch against the latest dev?
It is great work,
Cheers
Phil
Comment #2
alibama commentedI've added this to the /sites/all/modules/rules/modules/node_convert.rules.inc and don't see the changes in my rules actions - is this the correct place to have put this file? Thank you
Comment #3
zil.arman commentedI believe this file should be added to the '/sites/all/modules/node_convert' directory.
Comment #4
alcroito commentedThanks, committed into DEV.
Comment #5
zil.arman commentedIt works great with the Rules module, but cannot handle two actions in the row (like 'set data value' + node conversion), requires to create an additional rule.