You are here

function node_convert_convert_nodes_using_template in Node Convert 7

Same name and namespace in other branches
  1. 6 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 call to node_convert_convert_nodes_using_template()
node_convert_convert_nodes_using_template_rules_callback in ./node_convert.rules.inc
Takes rules action parameters and passes them to the convert function.
1 string reference to 'node_convert_convert_nodes_using_template'
node_convert_node_operations in ./node_convert.module
Implements hook_node_operations().

File

./node_convert.module, line 485

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,
      ));
    }
  }
  return TRUE;
}