function node_convert_conversion_form in Node Convert 6
Same name and namespace in other branches
- 5 node_convert.module \node_convert_conversion_form()
- 7 node_convert.forms.inc \node_convert_conversion_form()
1 string reference to 'node_convert_conversion_form'
- node_convert_menu in ./node_convert.module
- Implementation of hook_menu().
File
- ./node_convert.module, line 166
- The node_convert module converts nodes from one type to another.
Code
function node_convert_conversion_form($form_state, $node) {
$form = array();
if (!isset($form_state['values']['step'])) {
$op = 'choose_destination_type';
}
elseif ($form_state['values']['step'] == 'choose_destination_type') {
$op = 'choose_destination_fields';
}
$form['step'] = array(
'#type' => 'value',
'#value' => $op,
);
$form['node'] = array(
'#type' => 'value',
'#value' => $node,
);
if ($op == 'choose_destination_type') {
$type = node_get_types('name', $node);
$form['current_type'] = array(
'#type' => 'markup',
'#value' => $type,
);
$types = node_convert_return_access_node_types('to');
if ($types != FALSE) {
$key = array_search($form['current_type']['#value'], $types);
if ($key !== FALSE) {
unset($types[$key]);
}
$options = $types;
$form['destination_type'] = array(
'#type' => 'select',
'#options' => $options,
'#title' => t("To what content type should this node be converted"),
);
}
else {
$form['destination_type'] = array(
'#type' => 'markup',
'#value' => t("You don't have access to any node types."),
);
}
}
elseif ($op == 'choose_destination_fields') {
$source_fields = content_types($node->type);
$source_fields = $source_fields['fields'];
if (count($source_fields) == 0) {
$form['no_fields'] = array(
'#type' => 'value',
'#value' => 'TRUE',
);
}
else {
$dest_fields = content_types($form_state['storage']['destination_type']);
$dest_fields = $dest_fields['fields'];
$i = 0;
foreach ($source_fields as $source_field) {
$i++;
$options = array();
$options['discard'] = 'discard';
$options[APPEND_TO_BODY] = t('Append to body');
$options[REPLACE_BODY] = t('Replace body');
foreach ($dest_fields as $dest_value) {
if ($source_field['type'] == $dest_value['type'] && $source_field['multiple'] == $dest_value['multiple']) {
$options[$dest_value['field_name']] = $dest_value['field_name'];
}
}
$form['source_field_' . $i] = array(
'#type' => 'value',
'#value' => $source_field['field_name'],
);
$form['dest_field_' . $i] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => $source_field['field_name'],
'#title' => $source_field['field_name'] . " " . t("should be inserted into"),
);
$temp_value = node_convert_get_field_value($node, $source_field);
$form['current_field_value_' . $i] = array(
'#type' => 'markup',
'#value' => '<div>' . t("Current value is:") . " <b>" . $temp_value . '</b></div>',
);
}
$form['number_of_fields'] = array(
'#type' => 'value',
'#value' => $i,
);
}
$hook_options = module_invoke_all('node_convert_change', array(
'dest_node_type' => $form_state['storage']['destination_type'],
), 'options');
if (!empty($hook_options)) {
$form['hook_options'] = $hook_options;
array_unshift($form['hook_options'], array(
'#value' => '<br /><strong>' . t("Also the following parameters are available:") . '</strong>',
));
$form['hook_options']['#tree'] = TRUE;
}
}
if ($op != 'choose_destination_fields' && isset($types) && $types != FALSE) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t("Next"),
);
}
elseif ($op == 'choose_destination_fields') {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t("Convert"),
'#weight' => 100,
);
}
return $form;
}