Commit e358ebae authored by Croitor Alexandru's avatar Croitor Alexandru
Browse files

#480106 by bitman, nohup: Fixed template conversion.

#540434 by bitman: Fixed default value for fields.
Minor refactoring, and text changes.
parent efbc87f6
......@@ -34,8 +34,8 @@ function node_convert_help($path, $arg) {
* Implementation of hook_init().
*/
function node_convert_init() {
require_once './'. drupal_get_path('module', 'node_convert') ."/includes/book.node_convert.inc";
require_once './'. drupal_get_path('module', 'node_convert') ."/includes/forum.node_convert.inc";
require_once './'. drupal_get_path('module', 'node_convert') .'/includes/book.node_convert.inc';
require_once './'. drupal_get_path('module', 'node_convert') .'/includes/forum.node_convert.inc';
}
/**
......@@ -213,29 +213,11 @@ function node_convert_conversion_form($form_state, $node) {
}
$form['source_field_'. $i] = array('#type' => 'value', '#value' => $source_field['field_name']); // Remember the source fields to be converted
// The select populated with possible destination cck fields for each source field
$form['dest_field_'. $i] = array('#type' => 'select', '#options' => $options, '#title' => $source_field['field_name'] ." ". t("should be inserted into"));
// If the destination node type has the same field as the source node type, the default value is set to it.
$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"));
// Print the current value of the source field
if ($source_field['type'] == "image") {
$temp_value = $node->{$source_field['field_name']}[0]['title'] ." ; ". $node->{$source_field['field_name']}[0]['filepath'];
}
elseif ($source_field['type'] == "link") {
$temp_value = $node->{$source_field['field_name']}[0]['url'] ." ; ". $node->{$source_field['field_name']}[0]['title'];
}
elseif ($source_field['type'] == "email") {
$temp_value = $node->{$source_field['field_name']}[0]['email'];
}
elseif ($source_field['type'] == "file_audio" || $source_field['type'] == "file_video") {
$temp_value = $node->{$source_field['field_name']}[0]['filename'] ." ". $node->{$source_field['field_name']}[0]['filemime'] ." ". $node->{$source_field['field_name']}[0]['filesize'] ." ". t("bytes");
}
elseif ($source_field['type'] == "nodereference") {
$temp_value = "nid: ". $node->{$source_field['field_name']}[0]['nid'];
}
elseif ($source_field['type'] == "userreference") {
$temp_value = "uid: ". $node->{$source_field['field_name']}[0]['uid'];
}
else $temp_value = $node->{$source_field['field_name']}[0]['value'];
if (empty($temp_value)) $temp_value = 'NULL';
$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);
......@@ -556,7 +538,7 @@ function node_convert_convert_action(&$node, &$context = array()) {
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['fields']['source'], $template['fields']['destination'], $template['data']['no_fields'], $template['data']['hook_options']);
$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 succesuful message
node_convert_messages($result, array('nid' => $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.
......@@ -745,7 +727,7 @@ function node_convert_messages($result, $params = array()) {
drupal_set_message(t("Conversion failed. Node nid @nid doesn't exist.", array('@nid' => $params['nid'])), 'error');
}
elseif ($params['display_success'] == TRUE) {
drupal_set_message(t("The node @nid has been converted succesufuly.", array('@nid' => $params['nid'])));
drupal_set_message(t("Node @nid has been converted succesufuly.", array('@nid' => $params['nid'])));
}
}
......@@ -861,13 +843,47 @@ function node_convert_return_access_node_types($direction) {
$list = array();
$types = node_get_types();
foreach ($types as $type => $parameters) {
if (user_access('convert '. $direction .' '. $type)) $list[$type] = $type;
if (user_access('convert '. $direction .' '. $type)) $list[$type] = $parameters->name;
}
if (!empty($list))
return $list;
else
return FALSE;
}
/**
* Returns a string contaning the value of the $field from the $node object.
*
* @param $node
* A $node object
* @param $field
* The field who's value to get.
* @return
* A string contaning the value of the $field from the $node object.
*/
function node_convert_get_field_value($node, $field) {
$value = '';
if ($field['type'] == "image") {
$value = $node->{$field['field_name']}[0]['title'] ." ; ". $node->{$field['field_name']}[0]['filepath'];
}
elseif ($field['type'] == "link") {
$value = $node->{$field['field_name']}[0]['url'] ." ; ". $node->{$field['field_name']}[0]['title'];
}
elseif ($field['type'] == "email") {
$value = $node->{$field['field_name']}[0]['email'];
}
elseif ($field['type'] == "file_audio" || $field['type'] == "file_video") {
$value = $node->{$field['field_name']}[0]['filename'] ." ". $node->{$field['field_name']}[0]['filemime'] ." ". $node->{$field['field_name']}[0]['filesize'] ." ". t("bytes");
}
elseif ($field['type'] == "nodereference") {
$value = "nid: ". $node->{$field['field_name']}[0]['nid'];
}
elseif ($field['type'] == "userreference") {
$value = "uid: ". $node->{$field['field_name']}[0]['uid'];
}
else $value = $node->{$field['field_name']}[0]['value'];
if (empty($value)) $value = 'NULL';
return $value;
}
/**
* Loads a conversion template array using template_id.
......@@ -924,7 +940,7 @@ function node_convert_convert_nodes_using_template($nodes, $template_id) {
$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);
drupal_set_message(t("You don't have permission to use this conversion template."), 'warning', FALSE);
return FALSE;
}
......@@ -932,11 +948,11 @@ function node_convert_convert_nodes_using_template($nodes, $template_id) {
$node = node_load($nid);
// The source type of the given node doesn't match the template one, so we discard it with a message
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');
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['fields']['source'], $template['fields']['destination'], $template['data']['no_fields'], $template['data']['hook_options']);
// We display errors if any, or the default succesuful message
$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 there are any, or the default succesuful message
node_convert_messages($result, array('nid' => $nid));
}
}
......
......@@ -73,7 +73,7 @@ class NodeConvertTestCase extends DrupalWebTestCase {
$edit['destination_type'] = $type2_name;
$this->drupalPost('node/'. $node->nid .'/convert', $edit, t("Next"));
$this->drupalPost(NULL, array(), t("Convert"));
$this->assertText(t("The node @nid has been converted succesufuly.", array('@nid' => $node->nid)), t("Simple node conversion ui test passed."));
$this->assertText(t("Node @nid has been converted succesufuly.", array('@nid' => $node->nid)), t("Simple node conversion ui test passed."));
$result = db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $node->nid));
$this->assertEqual($result, $type2_name, t("The converted node type is equal to the destination node type."));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment