function node_convert_add_template_submit in Node Convert 6
Same name and namespace in other branches
- 7 node_convert.admin.inc \node_convert_add_template_submit()
File
- ./
node_convert.module, line 409 - The node_convert module converts nodes from one type to another.
Code
function node_convert_add_template_submit($form, &$form_state) {
if ($form_state['values']['step'] == 'choose_destination_type') {
$form_state['rebuild'] = TRUE;
$form_state['storage']['template_name'] = $form_state['values']['template_name'];
$form_state['storage']['source_type'] = $form_state['values']['source_type'];
$form_state['storage']['dest_type'] = $form_state['values']['dest_type'];
$form_state['storage']['create_action'] = $form_state['values']['create_action'];
}
elseif ($form_state['values']['step'] == 'choose_destination_fields') {
if ($form_state['values']['no_fields'] == FALSE) {
// If there are cck fields that can to be converted
for ($i = 1; $i <= $form_state['values']['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;
}
$fields = array(
'source' => $source_fields,
'destination' => $dest_fields,
);
$data = array(
'fields' => $fields,
'hook_options' => $hook_options,
'no_fields' => $form_state['values']['no_fields'],
);
$data = serialize($data);
db_query("INSERT INTO {node_convert_templates} (name, source_type, destination_type, data) VALUES ('%s', '%s', '%s', '%s')", $form_state['storage']['template_name'], $form_state['storage']['source_type'], $form_state['storage']['dest_type'], $data);
drupal_set_message(t("Template created successfully."));
if ($form_state['storage']['create_action'] == 1) {
$template_id = db_last_insert_id('node_convert_templates', 'nctid');
actions_save('node_convert_convert_action', 'node', array(
'template' => $template_id,
), 'Convert ' . $form_state['storage']['template_name'], NULL);
}
// We clear the storage so redirect works
$form_state['storage'] = array();
$form_state['redirect'] = 'admin/build/node_convert_templates';
}
}