Problem/Motivation
Say you have a field on both the article and basic page bundles but only the article bundle is translatable. Calling isTranslatable()
on the field config for the basic page bundle will return true. This is the problem. If the basic page bundle becomes translatable (but not the field itself), isTranslatable()
correctly returns false. So basically, as @plach said, the translatability is inherited from the field storage if they are not configured in the UI.
Proposed resolution
I believe it doesn't make sense for a field config to call itself translatable if it is in fact not. But I also probably am missing a lot of context info as to why this is. So it's very much open to discussion.
Remaining tasks
Discuss this issue and come to an agreement on the matter.
User interface changes
None.
API changes
Unclear.
Original report by @Upchuk
Comment | File | Size | Author |
---|---|---|---|
#29 | reroll_diff_drupal-n2457787-18_2457787-29.txt | 2.28 KB | yogeshmpawar |
#29 | 2457787-29.patch | 1.93 KB | yogeshmpawar |
#18 | drupal-n2457787-18.patch | 2.23 KB | DamienMcKenna |
#18 | drupal-n2457787-18.interdiff.txt | 1.6 KB | DamienMcKenna |
#18 | drupal-n2457787-18.test-only.patch | 1.6 KB | DamienMcKenna |
Comments
Comment #1
plachA possible solution to this issue would certainly be taking also bundle translatability into account: if a field definition is attached to a bundle and the bundle is not translatable then we would return FALSE. OTOH
FieldDefinitionInterface::isTranslatable()
is called a lot on multilingual sites (see ContentEntityBase::getTranslatedField()), so we should probably figure out in which cases this issue can cause serious problems, before trying to change the current status.Comment #8
DamienMcKennaThis is triggering a problem for me on a site with Paragraphs: #2999822: Ignore translation logic if translation system disabled
Comment #9
DamienMcKennaI'm specifically running into this in Entity Reference Revisions (entity_reference_revisions) where EntityReferenceRevisionsItem::preSave() checks the field's definition via getFieldDefinition(), checks isTranslatable() and will return either TRUE or FALSE.
Comment #10
DamienMcKennaI wonder if part of the problem is that FieldStorageConfig::isTranslatable() only checks $this->translatable rather than following similar logic to ConfigEntityBase::isTranslatable():
Comment #11
DamienMcKennaWould this be acceptable? It replicates the code from ContentEntityBase::isTranslatable() and adds on an extra && $this->translatable in case the config was set to be translated.
Comment #12
DamienMcKennaThe code in #11 could / should probably be improved upon.. but it at least checks the system translations.
Comment #14
DamienMcKennaI guess not ;-)
Comment #15
DamienMcKennaTrimmed down patch so now it just checks $this->languageManager()->isMultilingual() and $this->translatable.
Comment #17
plachDidn't look at the patches closely yet, but I think it's useful to point out that the field storage definition's
translatable
property is meant to tell whether the field storage supports translation. The actual field runtime configuration should not affect this as we don't change the field storage depending on that.OTOH it makes sense to tie field translatability to bundle translatability when dealing with field definitions as this is a per-bundle setting. I'm only afraid of possible BC issues.
Comment #18
DamienMcKennaA minor adjustment to the test, this confirms that the field is not translatable before the additional languages are added.
Comment #21
DamienMcKenna@plach: That's a good point. I suppose it could also be handled in Entity Reference Revisions, so maybe instead of $this->getFieldDefinition()->isTranslatable() it should be checking the instance?
Comment #28
larowlanIs this still an issue @DamienMcKenna?
Comment #29
yogeshmpawarUpdated patch with reroll diff added.
Comment #31
larowlanFor #28
Comment #34
DamienMcKennaI no longer have access to the site this problem first showed up for me, and I haven't ran into the problem on any other site since; that said, every site I work on either has zero translation or one extra language with translation enabled on all content types, I still think the original bug is a valid scenario.