You are here

function node_convert_convert_action in Node Convert 7

Same name and namespace in other branches
  1. 6 node_convert.module \node_convert_convert_action()

Implements hook_action, exposing predefined conversion templates as actions.

1 string reference to 'node_convert_convert_action'
node_convert_add_template_submit in ./node_convert.admin.inc
Submit callback for adding a new template.

File

./node_convert.module, line 247

Code

function node_convert_convert_action(&$node, &$context = array()) {
  if ($context['template'] === "0") {
    drupal_set_message(t("Dummy template. No action is being performed."), 'warning', FALSE);
    return FALSE;
  }
  $template = node_convert_load_template($context['template']);
  $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;
  }
  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 any, or the default success message
    node_convert_messages($result, array(
      'nid' => $node->nid,
    ));

    // This is node_load is necessary. It loads the new data from the DB, which gets passed down the action chain by reference, where it is saved.
    $node = node_load($node->nid, NULL, TRUE);
  }
  return TRUE;
}