Download & Extend

Changing the Language of a node via language assignment deletes the content on the edit page

Project:Language Assignment
Version:7.x-1.2
Component:Code
Category:bug report
Priority:critical
Assigned:Andrew Schulman
Status:needs review

Issue Summary

I changed all my blog entries (custom content type) from English to Language neutral. I can view the pages as normal, but when I try to edit them the text fields are empty. Saving the node in this state will cause the content to be lost completely except for the title.

Comments

#1

The same happened to mee too :(

#2

Changing the language back solves this > so you have at least your content back.

#3

Priority:normal» major
Assigned to:Anonymous» Andrew Schulman

#4

The same happened to mee too . So, I can not edit switched to other language content.

#5

Component:Miscellaneous» Code

Thanks for your patience y'all, and sorry for the trouble. This is a pretty major bug. I haven't had time to look at it before now, but I'm looking it now and I see the problem. I should have a fix ready within the next day.

#6

I just committed a fix for this bug. In my testing it works. Those of you who've observed this problem, please also test the fix and let me know if it works for you. To test it:

  1. Install the next 7.x-1.x-dev release when it becomes available (within the next 12 hours), or, if you prefer, apply the patch.
  2. Clear your site's cache ("Clear all caches" at admin/config/development/performance).
  3. Go to admin/content, select some nodes, and change their languages.
  4. Edit the nodes, and check that their content is still present in the edit block.

This bug doesn't occur in D6.

#7

Marking fixed; please let me know if you think otherwise. I'm going to roll a new release within the next few days.

#8

Status:active» fixed

Fixed in 7.x-1.2.

#9

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#10

Version:7.x-1.1» 7.x-1.2
Status:closed (fixed)» active

Sorry to reopen. I would like to report that it deletes the contents both from edit and node view pages. Mostly deleting body and simple text fields.

Thanks

#11

Ugh, that's bad. My apologies.

I'll get to this as soon as I can, but it's going to be a few days at least. Meanwhile, can you please tell me what other multilingual modules you have installed?

#12

Hi, thanks.

I installed regular combo: i18n + Variable, and languageassign.

This module can be very useful after bulk imports or migration, so would love to see this functional. Thanks again

#13

Status:active» postponed (maintainer needs more info)

I'm trying to reproduce this, and so far I can't. I've installed i18n, variable, and languageassign; activated all of the i18n submodules; and changed a node from English to French. After that I can still view and edit the node, and its content is still there.

I want to fix this problem, but there's not much I can do if I can't reproduce it. Any other suggestions for reproducing it would be appreciated. Are you sure you're using version 7.x-1.2? Cleared cache?

#14

I would say that in most cases, this module is too dangerous to use unless you deeply understand the drupal field language storage, and have exactly the same translation environment and strategy as the module expects.

After using the module, all field api fields are still attached to the node, but they are still set as as the first language. This module does not change the language of the field values.

Basically, the easiest way to see this is to create content with drupal set in various languages. Then use this module to mass update the language of nodes. Other than the body, most fields on those nodes will appear empty/unset (taxonomy, text fields etc).

In my case I had imported a lot of content using feeds which was set to language "und". After changing content to german "de" using this module the edit forms didn't register any of the imported values for most fields. Using the devel module, one could see that the values were still there, but had been left as "und".

#15

It seems as if the node fields are not being assigned to the proper language when you change the language of it.

It only affects added fields, not body and title.

#16

I'm also very interested in a fix, isn't there a way to do a node_load and emulate an alteration via the node edit form? The module needs to be aware of some fields being "untranslatable" (== always "und"), the easiest way would be to let i18n/core do the magic and just edit a node and send it back via the form_submit, but I'm not that familier with drupal and multilanguage..

Also see this related fix for images being deleted: #1261090: Images deleted after changing language of a node

Greetings Wappie

#17

There should be a warning on the project page since the module isn't currently stable

#18

Priority:major» critical
Status:postponed (maintainer needs more info)» needs work

a total of 50 of my contents are lost. Everything is ok exept the body fields. nothing is showing up in the body field.

My environment is just standard. i used i18, variables and language assign.

I'm absolutely frustrated and do not know what to do.

I think assigning language twice causes the problem.

#19

try with a fresh installation and activate language. I use just bengali and english.
after adding bengali language didn't activate language for some node types (i.e- i didn't enable multilingual in structure>content_type>edit).

I've assigned bengali to language nutral contents.
I assigned same language twice to some contents.

50 of my contents are lost.
my messages were off in a production site.

i think this will help you to reproduce the bug.

#20

All, I apologize that it's taken me so long to attack this bug. I see the problem and will work to fix is as soon as I can. Until then, I've withdrawn the Drupal 7 release.

mahfuzur, I believe that your content is still present. If you use Language Assignment again to change the nodes' language back to its original value, your content should still be there.

#21

subs.

#22

Here is a possible fix:Replace the languageassign_node_presave function. (This code is based on what you would find in the locale.inc from core when you change the lang of a node)

<?php
/**
* 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
    
     
$node->language = $new_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 != $new_language) {
         
$node->{$field_name}[$new_language] = $node->{$field_name}[$previous_language];
         
$node->{$field_name}[$previous_language] = array();
        }
      }    
    }  
  }
}
?>

Still dont use this function on field translation. Use it when using node translation only.
Read this to understand the difference between field and node translation : http://hojtsy.hu/blog/2011-jan-31/drupal-7039s-new-multilingual-systems-...

#23

...following.

#24

Could you please disable the download for this module? I used the D6 version / installed D7 via drush and got my content deleted. I know i can set it back but it will cost me a couple of hours :(

#25

#26

+1

#27

Subscribing... I'm writing a book on Drupal 7 i18n and want to include this module in it!

[NOTE: If you just want to "subscribe" to this discussion, click the "FOLLOW" button at the top right of this page.]

Kristen

#28

Status:needs work» needs review

Dear domidc, Thanks for your work.
I tuned your code and tested. And i made a patch file.

It works fine and don't print Unindexed warning.

AttachmentSize
languageassign-fix_content_delete-1086454-28.patch 2.91 KB

#29

A little change added.
Calling unset function before compare old and new language.

AttachmentSize
languageassign-fix_content_delete-1086454-29.patch 2.87 KB

#30

I just did a bulk change from Language neutral to English and then back (both via the tool and another node manually) and was not able to view the original body content. So, in my case, changing the language back did not solve the problem.

#31

Would you mind provide instructions for bringing the content back?

#32

@barami: Thanks for your patch #29, I've did some language assignments without any data loss.

#33

I tried applying patch from #29 on the latest 7.x dev version and the patch failed.

[kristen:modules]$ patch -p1 < languageassign-fix_content_delete-1086454-29.patch
patching file languageassign.module
Hunk #1 FAILED at 54.
Hunk #2 FAILED at 165.
2 out of 2 hunks FAILED -- saving rejects to file languageassign.module.rej

#34

The patch works on 7.x-1.2 and fixes the loss of data from the body field for me.

#35

@barami - can you reroll the patch against the dev version because it will need to be committed against dev in order to get in. Thanks!

#36

@Kristen Pol
Hm?
Does your repository pushed to remote repository? I pulled repository and applied patch now, But, It works fine.
I tried master branch and applied tarball 7.x-1.x-dev published on Jun 17. Also i tried on tag 7.x-1.2. Each case are succesfully applied with no errors.

If you were pulled your repository to remote, i will pull and reroll the patch.

#37

@barami - The patch was applied in the wrong directory (thus, the error). I have now applied the patch without errors.

I tested 2 scenarios:

1) Language assignment enabled but without translation.

This works as expected. I was able to change the language of nodes without the body disappearing.

2) Translation enabled.

This one is tricky because I'm not sure how it is supposed to handle the following situation:

a) I have a Burmese node.

b) I have an English node.

c) These are translations of each other.

d) I use language assignment to assign English to the Burmese node.

e) Now I have 2 English nodes in the same translation set.

Should there be a warning/error message?

#38

Is this issue even limited to/related to languageassign.module?

Entity Translation all by itself does this, under certain conditions.

nobody click here