I have a problem when running a Feeds import to create Mongo Node entities, which should be translatable later on.

If I'm setting the default language at /admin/config/regional/entity_translation to ENTITY_TRANSLATION_LANGUAGE_DEFAULT or ENTITY_TRANSLATION_LANGUAGE_CURRENT it works fine.

But if I set it to ENTITY_TRANSLATION_LANGUAGE_AUTHOR and I'm running the import as a user which has no language set (ex. superadmin) or as an anonymous user (ex. Beanstalkd background job) then there is no $GLOBALS['user']->language in getDefaultLanguage() from EntityTranslationDefaultHandler so the function returns an empty string.

Thus, no data will be stored in the entity_translation table in the database associated to the current entity I'm creating.
(This way I get an access denied error on the edit and translate tabs of the entity. #2467509: Access Denied on edit / translate tabs of entity)

Shouldn't this code:

case ENTITY_TRANSLATION_LANGUAGE_AUTHOR:
  $langcode = $GLOBALS['user']->language;
  break;

be something like this:

case ENTITY_TRANSLATION_LANGUAGE_AUTHOR:
  if (isset($this->entity->uid) {
    $account = user_load($this->entity->uid);
    if (isset($account->language) && $account->language) {
      $langcode = $account->language;
    }
     else {
       // Fall back to current / default language?
    }
  }
  break;

Comments

odegard’s picture

Version: 7.x-1.0-beta4 » 7.x-1.x-dev
Assigned: Unassigned » odegard
StatusFileSize
new1.16 KB

I'm having this issue too. Here's a patch.

odegard’s picture

Assigned: odegard » Unassigned
Status: Active » Needs review

Tested and logs are clean once more!

odegard’s picture

Well that was embarrassing. Misspelling.

odegard’s picture

Status: Needs review » Needs work

Sorry again, this need a lot more work.

stefanos.petrakis’s picture

Status: Needs work » Needs review
StatusFileSize
new478 bytes

Rerolling this, with some simplistic sanity check at the end of getDefaultLanguage() in order to solve this in a more generic way.

plach’s picture

StatusFileSize
new1.05 KB

What about this? It further simplifies the ::getDefaultLanguage() logic.

@odegard can you let us know whether this is still fixing your issue?

plach’s picture

Title: getDefaultLanguage » Ensure ::getDefaultLanguage() always returns a valid value
odegard’s picture

StatusFileSize
new2.49 KB

Unfortunately, we don't use this code anymore but the new logic is sound.

I've made an attempt to simplify it further getting rid of the if/else all together. I believe the code is easier to read and understand now.

I don't think initializing $langcode = NULL is strictly needed in my patch but it's good practice so I kept it from your patch.