You are here

function node_convert_conversion_form_submit in Node Convert 6

Same name and namespace in other branches
  1. 5 node_convert.module \node_convert_conversion_form_submit()
  2. 7 node_convert.forms.inc \node_convert_conversion_form_submit()

File

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

Code

function node_convert_conversion_form_submit($form, &$form_state) {

  // Remember the destination type
  if ($form_state['values']['step'] == 'choose_destination_type') {
    $form_state['rebuild'] = TRUE;
    $form_state['storage']['destination_type'] = $form_state['values']['destination_type'];
  }
  elseif ($form_state['values']['step'] == 'choose_destination_fields') {

    // Information needed in the convert process: nid, vid, source type, destination type
    $dest_node_type = $form_state['storage']['destination_type'];
    $node = $form_state['values']['node'];
    $nid = $node->nid;
    $vid = $node->vid;
    $source_node_type = $node->type;
    $no_fields = $form_state['values']['no_fields'];
    $number_of_fields = $form_state['values']['number_of_fields'];
    if ($no_fields == FALSE) {

      // If there are cck fields that can to be converted
      for ($i = 1; $i <= $number_of_fields; $i++) {
        $source_fields[] = $form_state['values']['source_field_' . $i];

        //  Source fields
        $dest_fields[] = $form_state['values']['dest_field_' . $i];

        // Destination fields
      }
    }
    if (!empty($form['hook_options'])) {
      $hook_options = $form_state['values']['hook_options'];
    }
    else {
      $hook_options = NULL;
    }
    $result = node_convert_node_convert($nid, $dest_node_type, $source_fields, $dest_fields, $no_fields, $hook_options);

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

    // We clear the storage so redirect works
    $form_state['storage'] = array();
    $form_state['redirect'] = "node/" . $nid;
  }
}