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...

Command icon 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

andreyjan created an issue. See original summary.

andreyjan’s picture

There 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.

andreyjan’s picture

Refactored #2 patch by moving the logic to widgets base class.

nicrodgers’s picture

Hi @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.

nicrodgers’s picture

I think the revision issue I mention above is a core issue, see https://www.drupal.org/project/drupal/issues/3007233

markdatter’s picture

Hi @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.

nicrodgers’s picture

Issue tags: +Needs tests

I 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).

andreyjan’s picture

Test only and the combined test/fix patches

The last submitted patch, 8: inline_entity_form-translatable_revisions-2989028-8-test_only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

texas-bronius’s picture

Does 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.

rp7’s picture

Thank you for your efforts @andreyjan.

Re-rolled patch in #8 against current dev version.

  • podarok committed dcdd91ed on 2.0.x authored by rp7
    Issue #2989028 by andreyjan, rp7, nicrodgers, texas-bronius: Fix...
podarok’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Status: Needs review » Fixed

#11 is in
tnx

lowfidelity’s picture

Status: Fixed » Needs work

The patch #8 creates /src/Tests/ContentModerationTranslationTest.php. ContentModerationTranslationTest extends InlineEntityFormTestBase which 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:12

See this result for example: https://www.drupal.org/pift-ci-job/2666453

podarok’s picture

Priority: Normal » Major
Issue tags: +Needs tests
lowfidelity’s picture

The test in ContentModerationTranslationTest.php and InlineEntityFormTestBase require some refactoring, as InlineEntityFormTestBase extends WebDriverTestBase.

ContentModerationTranslationTest.php requires a use Drupal\Tests\inline_entity_form\FunctionalJavascript\InlineEntityFormTestBase; and the deprecated calls to drupalPostAjaxForm(..) need to replaced with drupalPostForm.

See https://www.drupal.org/docs/automated-testing/converting-simpletests-to-... .

shivam_tiwari made their first commit to this issue’s fork.

shivam_tiwari’s picture

Status: Needs work » Needs review
podarok’s picture

Status: Needs review » Needs work

https://www.drupal.org/pift-ci-job/2668244

> Drupal\Core\Composer\Composer::upgradePHPUnit
PHP Fatal error:  Declaration of Drupal\inline_entity_form\Tests\ContentModerationTranslationTest::setUp() must be compatible with Drupal\Tests\inline_entity_form\FunctionalJavascript\InlineEntityFormTestBase::setUp(): void in /var/www/html/modules/contrib/inline_entity_form/src/Tests/ContentModerationTranslationTest.php on line 30
lowfidelity’s picture

setUp() must be defined as protected function setUp(): void {

I also see some other errors when I open ContentModerationTranslationTest.php in Vscode:

Undefined method 'drupalPostAjaxForm'
Undefined method 'drupalPostAjaxForm'
Undefined method 'assertTrue'

shivam_tiwari’s picture

Status: Needs work » Needs review
lowfidelity’s picture

Thank you @shivam_tiwari. Did not run a test but code looks good to me now.

@podarok, could you please merge and run a test?

podarok’s picture

Status: Needs review » Fixed

merged
checking

podarok’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

geek-merlin’s picture

Version: 2.0.x-dev » 3.0.0-rc15
Status: Closed (fixed) » Needs work

Bulk reopen.

geek-merlin’s picture

Version: 3.0.0-rc15 » 3.x-dev
falc0’s picture

For me some fields where not hidden when they should've been hidden. Updated the patch from #11 to fix that.

defcon0’s picture

At 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?