You are here

function node_convert_convert_nodes_using_template in Node Convert 6

Same name and namespace in other branches
  1. 7 node_convert.module \node_convert_convert_nodes_using_template()

Converts a list of nodes using a given template

Parameters

$nodes: An array containing a list of node nid's

$template_id: The template to use for conversion

Return value

FALSE if the user doesn't have permission to use the template.

1 string reference to 'node_convert_convert_nodes_using_template'
node_convert_node_operations in ./node_convert.module
Implementation of hook_node_operations().

File

./node_convert.module, line 1043
The node_convert module converts nodes from one type to another.

Code

function node_convert_convert_nodes_using_template($nodes, $template_id) {
  $template = node_convert_load_template($template_id);
  $access = node_convert_check_template_permission_user(array(
    'template' => $template,
  ));
  if ($access == FALSE) {
    drupal_set_message(t("You don't have permission to use this conversion template."), 'warning', FALSE);
    return FALSE;
  }
  foreach ($nodes as $nid) {
    $node = node_load($nid);

    // The source type of the given node doesn't match the template one, so we discard it with a message
    if ($node->type != $template['source_type']) {
      drupal_set_message(t("Node %nid doesn't match the template source type. Discarded.", array(
        'nid' => $node->nid,
      )), 'warning');
    }
    else {
      $result = node_convert_node_convert($node->nid, $template['destination_type'], $template['data']['fields']['source'], $template['data']['fields']['destination'], $template['data']['no_fields'], $template['data']['hook_options']);

      // We display errors if there are any, or the default success message
      node_convert_messages($result, array(
        'nid' => $nid,
      ));
    }
  }
}