Closed (duplicate)
Project:
Language Assignment
Version:
7.x-1.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Reporter:
Created:
27 Sep 2011 at 09:31 UTC
Updated:
28 Sep 2011 at 16:47 UTC
This module does an invalid assignment:
The hook node presave should contain this. (As done by core.)
/**
* Implements hook_node_presave().
* Updates the nody and body languages.
*/
function languageassign_node_presave($node) {
if (property_exists($node, 'languageassign_langcode')) {
if (field_has_translation_handler('node', 'locale')) {
$new_language = $node->languageassign_langcode;
$previous_language = $node->language;
unset($node->languageassign_langcode);
$available_languages = field_content_languages();
list(, , $bundle) = entity_extract_ids('node', $node);
foreach (field_info_instances('node', $bundle) as $instance) {
$field_name = $instance['field_name'];
$field = field_info_field($field_name);
// Handle a possible language change: new language values are inserted,
// previous ones are deleted.
if ($field['translatable'] && $previous_language != $node->language) {
$form_state['values'][$field_name][$new_language] = $node->{$field_name}[$previous_language];
$form_state['values'][$field_name][$previous_language] = array();
}
}
}
}
}
When only updating the node language, the language of the fields was not updated. When not using field translations and only node translations the language of the nodes and the fields (when translatable) should all be the same.
Comments
Comment #1
domidc commentedThe actual assignment of the lang was missing
Comment #2
Andrew Schulman commentedThanks for posting a solution. Agree that this is a critical bug. It's actually a dup of #1086454: DATA-LOSS: Changing the Language of a node via language assignment deletes the content on the edit page. Please post your fix there.
I will get to this as soon as my time permits - this weekend I believe.