function node_convert_add_template_submit in Node Convert 7
Same name and namespace in other branches
- 6 node_convert.module \node_convert_add_template_submit()
Submit callback for adding a new template.
File
- ./
node_convert.admin.inc, line 305 - Administration page callbacks for the node_convert module.
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']['machine_name'] = $form_state['values']['machine_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') {
$no_fields = $form_state['values']['no_fields'];
// If there are fields that can to be converted
if ($no_fields == FALSE) {
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' => $no_fields,
);
$data = serialize($data);
$is_editing_mode = isset($form_state['storage']['is_editing_mode']);
$id = node_convert_save_template($form_state['storage']['template_name'], $form_state['storage']['machine_name'], $form_state['storage']['source_type'], $form_state['storage']['dest_type'], $data, $is_editing_mode);
ctools_include('export');
ctools_export_load_object_reset(NODE_CONVERT_TEMPLATE_TABLE);
if ($is_editing_mode) {
drupal_set_message(t("Template updated successfully."));
}
else {
drupal_set_message(t("Template created successfully."));
}
// @TODO Fix being able to create action when editing. Need to find template_id.
if ($form_state['storage']['create_action'] == 1 && !$is_editing_mode) {
$template_id = $id;
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/structure/node_convert_templates';
}
}