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;
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | entity_translation-ensure-getDefaultLanguage-is-valid-2467515-8.patch | 2.49 KB | odegard |
Comments
Comment #1
odegard commentedI'm having this issue too. Here's a patch.
Comment #2
odegard commentedTested and logs are clean once more!
Comment #3
odegard commentedWell that was embarrassing. Misspelling.
Comment #4
odegard commentedSorry again, this need a lot more work.
Comment #5
stefanos.petrakisRerolling this, with some simplistic sanity check at the end of
getDefaultLanguage()in order to solve this in a more generic way.Comment #6
plachWhat about this? It further simplifies the
::getDefaultLanguage()logic.@odegard can you let us know whether this is still fixing your issue?
Comment #7
plachComment #8
odegard commentedUnfortunately, 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.