Problem/Motivation
Drupal 8.5 introduced changes in multilingual fields approach. Fields which are marked non-translatable are hidden in translation edit form. When used in combination with content moderation 'Hide non translatable fields on translation forms' setting is enforced. Thus it becomes impossible to edit entity translations.
Steps to reproduce
1. Install Drupal 8.5.
2. Enable multilingual modules, add at least 2 languages.
3. Enable content moderation.
4. Create a content type with entity reference field using inline_entity_form widget.
5. Make referenced entity type translatable and entity reference field not-translatable.
6. Create a node and add a translation to it.
Result::
When you edit translation for for this node, entity reference field will be hidden and you'll not be able to edit the entity translation.
Note:
There is a thread with the same issue for paragraphs https://www.drupal.org/docs/8/modules/paragraphs/multilingual-and-conten...
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | interdiff_11-30.txt | 879 bytes | falc0 |
| #30 | inline_entity_form-translatable_revisions-2989028-30.patch | 12.94 KB | falc0 |
| #11 | inline_entity_form-translatable_revisions-2989028-11.patch | 12.67 KB | rp7 |
| #8 | inline_entity_form-translatable_revisions-2989028-8-test_only.patch | 11.7 KB | andreyjan |
Issue fork inline_entity_form-2989028
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 #2
andreyjan commentedThere are core patches already committed to Drupal 8.6 which fix this issue:
Respect existing #multilingual property in content_translation_form_alter()
https://www.drupal.org/project/drupal/issues/2975762
FieldItemList::equals is sufficient from the storage perspective but not for code checking for changes
https://www.drupal.org/project/drupal/issues/2826021
Attaching a patch which adds #multilingual property to widget for allowing to edit referenced entities translations.
Patches for the above core issue should be also applied to core 8.5.
Things still needed to be checked
How this works with revisions.
Comment #3
andreyjan commentedRefactored #2 patch by moving the logic to widgets base class.
Comment #4
nicrodgersHi @andreyjan, I've been testing this today. Thanks for the patch.
This works well for when you want to edit a translation of a published node.
Where it does not work is if you are using revisions, such as with content moderation.
Here's a scenario that doesn't work:
1. add a new node with an IEF field, publish it
2. translate and publish it
3. create a new draft in the original language, add a new value to the IEF field, do not publish
4. create a new draft translation.
Actual result:
You do not see the newly added value in the IEF field
Expected result:
You should see the newly added value in the IEF field, so that you can translate it.
Comment #5
nicrodgersI think the revision issue I mention above is a core issue, see https://www.drupal.org/project/drupal/issues/3007233
Comment #6
markdatter commentedHi @nicrodgers, Does the patch in #3 result in a net improvement to the module functionality, or does it introduce a new problem that wasn't there before? I am using the patch and would love to see it committed while we wait for the core issue with revisions to be resolved.
Comment #7
nicrodgersI think the patch in #3 is still worth moving forwards with, I mentioned the revision scenario in #4/#5 mainly as a heads-up for anyone who comes here looking for/expecting a solution for that. That's a core issue anyway.
I think the best way to move this issue forwards to get it ready for merging is to create some tests that demonstrate the problem (and the fix).
Comment #8
andreyjan commentedTest only and the combined test/fix patches
Comment #10
texas-bronius commentedDoes this issue queue refer to the parent form entity reference field (and therefore its IEF) being hidden when the field is not translatable or something on the embedded IEF? I am looking for the former.
Note that currently (and with the patch in #8 above), my host entity form is translatable and has a non-translatable, multivalue entity reference field which utilized IEF to create/edit. Should be irrelevant whether the referenced IEF entity type is translatable. When I add or edit a translation to my parent entity:
Expected: The embedded IEF for this non-translatable entity reference field should not show either values, Add, or Edit.
Instead: Two observations: 1. I do not see existing values from the Original Translation but can Add a new reference with IEF. 2. And when I do, the unseen Original Translation references get clobbered, and now all translations point to the one(s) added in the translation.
Based on the description of this issue, these sound related, but if I am talking about something else, please clarify in this issue's description. As for my particular issue, I've filed my separate concern as #3108400: Inline Entity Form: Hide widget when host entity form is not original language, and host reference field is not translatable and uploaded a patch that works for my case. I hope it helps, and I hope it can be improved and approved in its simplicity.
Comment #11
rp7 commentedThank you for your efforts @andreyjan.
Re-rolled patch in #8 against current dev version.
Comment #13
podarok#11 is in
tnx
Comment #14
lowfidelityThe patch #8 creates
/src/Tests/ContentModerationTranslationTest.php.ContentModerationTranslationTestextendsInlineEntityFormTestBasewhich is not defined in this namespace.This breaks automatic tests on the 2.0.x branch:
PHP Fatal error: Uncaught Error: Class "Drupal\inline_entity_form\Tests\InlineEntityFormTestBase" not found in /var/www/html/modules/contrib/inline_entity_form/src/Tests/ContentModerationTranslationTest.php:12See this result for example: https://www.drupal.org/pift-ci-job/2666453
Comment #15
podarokComment #16
lowfidelityThe test in
ContentModerationTranslationTest.phpandInlineEntityFormTestBaserequire some refactoring, asInlineEntityFormTestBaseextendsWebDriverTestBase.ContentModerationTranslationTest.phprequires ause Drupal\Tests\inline_entity_form\FunctionalJavascript\InlineEntityFormTestBase;and the deprecated calls todrupalPostAjaxForm(..)need to replaced withdrupalPostForm.See https://www.drupal.org/docs/automated-testing/converting-simpletests-to-... .
Comment #19
shivam_tiwari commentedComment #20
podarokhttps://www.drupal.org/pift-ci-job/2668244
Comment #21
lowfidelitysetUp()must be defined asprotected function setUp(): void {I also see some other errors when I open
ContentModerationTranslationTest.phpin Vscode:Undefined method 'drupalPostAjaxForm'Undefined method 'drupalPostAjaxForm'Undefined method 'assertTrue'Comment #23
shivam_tiwari commentedComment #24
lowfidelityThank you @shivam_tiwari. Did not run a test but code looks good to me now.
@podarok, could you please merge and run a test?
Comment #25
podarokmerged
checking
Comment #26
podarokrun https://www.drupal.org/pift-ci-job/2668358
Comment #28
geek-merlinBulk reopen.
Comment #29
geek-merlinComment #30
falc0 commentedFor me some fields where not hidden when they should've been hidden. Updated the patch from #11 to fix that.
Comment #31
defcon0 commentedAt first, thanks for the patch, works great so far :) One thing still not working is that if the field references a media element containing an image file upload, in the translation record I can't delete the referenced item but only edit it.
Not sure if this only applies to referenced media entities but also for other ones.
Does anyone else have this behavior?