Problem/Motivation
When we have an entity that has the "fr" langcode on the server website and the "und" langcode on the client website, the sync fails with this error:
InvalidArgumentException : The entity cannot be translated since it is language neutral (und). dans Drupal\Core\Entity\ContentEntityBase->addTranslation()
This happens because ImportService::getProcessedEntity() sees that the entity does not already have a French translation so it calls addTranslation() on it, but this is not allowed for entities with a locked language.
Steps to reproduce
- Create a media with the "und" language and synchronize it to another website.
- Change the language to "fr" and synchronize it again.
Proposed resolution
ImportService::getProcessedEntity() should not add a translation when the existing entity has a locked language, it should instead change its language.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3277731-4.patch | 955 bytes | taras.suliatitskiy |
Issue fork entity_share-3277731
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
prudloff commentedComment #4
taras.suliatitskiy commentedPatch created.
Comment #6
grimreaperComment #7
grimreaperHi,
Thanks I reproduce the problem. Having entities in a locked language is not something frequent.
So I made some test and ok, if an entity is in language und, it can't have translation so no risk to have imported it previously in another language.
The problem may also happen is the following scenario:
Site 1:
- Entity A und
Site 2:
import entity
- Entity A und
Site 1:
- change default language
- Entity A en
- add translation
- Entity A fr
Site 2:
- try to import Entity A fr (which is not the default language on Site 1)
In this case, with the currently proposed solution, this will change the default langcode of the imported entity to the langcode of the translation being imported which this may not be what we want.
In DefaultDataProcessor.php, the default_langcode attribute is removed, but I think we still have access to the content_translation_source attribute which value is und in the case of the default translation and the source translation code if not.
I will try to poc something around that.
Comment #8
grimreaperI tried something like the following code.
And the problem is in the last else statement. So I guess that when having content switching from locked language to normal languages, this may not be a problem that the imported entity in language und, is overridden with new data set as default translation. In most cases I guess that the next import will be to update the default langcode.
So the issue "only" needs tests.
Comment #11
grimreaperComment #13
lawxen commentedI still got error when syncing a node again
InvalidArgumentException: Invalid translation language (und) specified. in Drupal\Core\Entity\ContentEntityBase->addTranslation() (line 952 of /var/www/html/docroot/core/lib/Drupal/Core/Entity/ContentEntityBase.php) [d96fafe1-837e-42f9-ad09-cb688adda8fc].Version : Drupal10 + entity_share 3.0
Comment #14
lawxen commentedContinue:
On ther sever side, I use jsonapi_extra hide the language field, then the client side will use the default languge to create the node, then sync again, error comes.