I created an action in Rules, which generates a duplicate of a node. If I am creating a node of the type "basic", it will duplicate the node for every taxonomy term. So when I have a node with three taxonomy terms, the action will generate three nodes.
The only difference are the taxonomy terms, because the created nodes should get the URL '/taxonomy-term1/node-title', '/taxonomy-term2/node-title', ...
My problem: If I have the taxonomy terms Taxonomy_Term1, Taxonomy_Term2 and Taxonomy_Term3, I get the following result:
/taxonomy-term1/node-title
/default/node-title
/default/node-title-0
I am thinking the problem lies in the array which was created from the latest nid. But when I am printing each term_name (to know what it looks like), the results are the Strings Taxonomy_Term1, Taxonomy_Term2 and so on.
function autocreatenode_rules_action() {
$nid = db_query_range("SELECT nid FROM {node} ORDER BY nid DESC", 0, 1)-> fetchField();
$string = token_replace('[node:field_tags]', array('node' => node_load($nid)));
$terms = explode(',', $string);
$i = 0;
foreach ($terms as $term_name) {
$i++;
}
if($i >= 2) {
foreach ($terms as $term_name) {
$node = new stdClass();
$node->type = 'basic';
$node->language = 'de';
node_object_prepare($node);
$node->title = 'Title';
$node->field_body[LANGUAGE_NONE][0]['value'] = 'Something in the body';
$menu = array();
$menu['link_title'] = 'Menu Link title';
$menu['description'] = '';
$menu['menu_name'] = 'main-menu';
switch($term_name) {
case 'Taxonomy_Term1':
$menu['plid'] = 5;
break;
case 'Taxonomy_Term2':
$menu['plid'] = 6;
break;
case 'Taxonomy_Term3':
$menu['plid'] = 7;
break;
default:
$menu['plid'] = 1;
}
$menu['enabled'] = 1;
$node->menu = $menu;
$node->status = 1;
$node->promote = 0;
$node->sticky = 0;
$node->comment = 2;
$node->uid = 1;
$node->date = 'complaint_post_date';
$node->created = strtotime('complaint_post_date');
$node = node_submit($node);
node_save($node);
}
}}