Problem/Motivation

#2494959: Add translation integration added support for translating referenced entities along with their 'parents'. This works well, except that it breaks the IEF widget when a new 'parent' entity in a non-default language is created.

Steps to reproduce:

  1. Install Drupal 8 with IEF.
  2. Make sure there are two content types, both translatable. Their languages must be configurable in their forms.
  3. Add an entity reference field to one of the content types, targeting the other type.
  4. Configure the ER field to use the Complex IEF widget.
  5. Add a node of the type with the ER field. Change the language to anything else but the default language, and add a new entity reference value.
  6. Confirm that the form does not appear. No errors are shown or logged.

Proposed resolution

Make TranslationHelper::isTranslating() return FALSE if the entity the form state is for is new.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Xano created an issue. See original summary.

Xano’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
1.27 KB

This is a proof-of-concept patch.

Xano’s picture

Status: Needs review » Needs work

The last submitted patch, 2: inline_entity_form_2747781_2.patch, failed testing.

Xano’s picture

Status: Needs work » Needs review
FileSize
1.29 KB
965 bytes
Xano’s picture

This leverages the existing test to create the error condition. We know it works if the test's original workflow does not fail, as demonstrated by the test-only patch.

Xano’s picture

FileSize
1.42 KB
2.36 KB

And now, new and improved, with patch and interdiff.

The last submitted patch, 6: inline_entity_form_2747781_6-test-only.patch, failed testing.

paulmckibben’s picture

Status: Needs review » Needs work

Thanks for the patch. Unfortunately, here is what happens when I try it. (Using latest 8.x-1.x-dev version of inline_entity_form plus the patch in #7)

1. When I create a translation and change the source language to a non-default language, the inline entity reference fields appear to update to the values corresponding to the new language.
2. However, when I save the translation and then view it, the values in the inline entity reference fields are for the default language, not the language I selected.

johnwebdev’s picture

We also have the same issue.

We have 2 languages enabled.
We have Inline Entity Forms installed.
We created two new content types where one has a object reference to the other. It uses IEF Complex.

We add a node in the primary language. (We don't fill any value in the IEF).
When we translate it's empty, no errors or logs.

If we update the original node with a value, the form is there, but we cannot add another entity to that translation. This is important, because we want the reference field to be translatable as well.

Xano’s picture

Assigned: Xano » Unassigned

Bump. We just ran into this problem again elsewhere, and I realized the patch had not been approved/improved yet.

@paulmckibben @johndevman: Could you extend the patch with a test case that does what you did and exposes the problem? If not, can you provide more detailed, explicit, step-by-step instructions on how to reproduce your problem on a clean installation using the latest Drupal 8.3.x-dev, and the latest Inline Entity Form 8.x-1.x-dev?

johnwebdev’s picture

Steps to reproduce:

1. I've downloaded Drupal 8.3.x-dev and latest Inline Entity Form 8.x-1.x-dev.
2. I installed with Minimal profile
3. I enabled Languages modules and added language Swedish. Now I have two languages English (default) and Swedish.
4. I create content type Foo which has translation enabled.
5. I create content type Bar which has translation enabled. I add a "Foo reference" field which has translation enabled.
6. I set Foo reference field to IEF Complex, and add setting: "Allow users to add existing nodes." only.
7. I verify that each content type has translation enabled for all fields.
8. I add a "Foo" node (English) and translates it to Swedish as well.
9. I add a "Bar" node (English) without adding any reference.
10. I translate Bar node to Swedish and cannot see IEF form at all.
11. I apply patch "inline_entity_form_2747781_6.patch" and checks again. Clears cache. No difference.
12. If I change the Foo reference to use "Autocomplete" form display instead, it works as expected.

I read through the parent issue, it seems like this is intended behavior (that the entity reference is not translatable itself). If so this could probably be ignored / moved to another issue.

ckaotik’s picture

Status: Needs work » Needs review
FileSize
2.38 KB

I have tried to descern the various translation use cases in #2836102: Translation behavior is broken in some use cases. As far as I can tell, this issue is indeed because of the isTranslating() detection. It works nicely for non-translatable fields but causes issues when the ER field is translatable.

As a workaround, I also check if the field is translatable, and if so don't apply this logic. However, this should still be solved generally for translatable fields, which is why I created the above mentioned issue.

  protected function isTranslating(FormStateInterface $form_state) {
    if (TranslationHelper::isTranslating($form_state) && !$this->fieldDefinition->isTranslatable()) {
      $translation_manager = \Drupal::service('content_translation.manager');
      $target_type = $this->getFieldSetting('target_type');
      foreach ($this->getTargetBundles() as $bundle) {
        if ($translation_manager->isEnabled($target_type, $bundle)) {
          return TRUE;
        }
      }
    }

    return FALSE;
  }

Status: Needs review » Needs work

The last submitted patch, 13: inline_entity_form-2747781-13.patch, failed testing.

ckaotik’s picture

Status: Needs work » Needs review
FileSize
2.29 KB

I'd better try with the correct patch file ...

Status: Needs review » Needs work

The last submitted patch, 15: inline_entity_form-2747781-15.patch, failed testing.

johnwebdev’s picture

@chaotik The patch seems to work fine from here. Shouldn't we use the issue #2822764 to keep on it though?

rockaholiciam’s picture

There are still a couple of things that need some work.

1. If I add a new parent node and change its language, although it now allows me to add referenced nodes (after applying patch in 16), but fails when you go and save the parent node. This happens when you have added a new referenced node instead of an existing one. Although it works with adding existing nodes but since interface language is different, the referenced nodes show up in interface language in the IEF (Complex), albeit they appear fine when viewing content.

2. Referenced entities although appear fine on node view for translated node, however in the IEF (complex), they appear to be referring to the entities source language.

3. If now a new reference is created in parents translation that doesnt exist in source language or hasnt yet been translated in source language, it appears fine in IEF complex edit form. If we now translate that referred entity and add it to source parent as well, it appears to be referring to the translated version while the translated version continues to refer to the correct version.

2 and 3 hint that somehow, the referenced entity created first is the one thats tracked within IEF (complex).

timodwhit’s picture

Status: Needs work » Postponed (maintainer needs more info)

I was not able to reproduce this on a clean install with the steps above. Are particular settings required to force this situation or is it possible that this was resolved in the releases after this issue was created?

rudins’s picture

Let's not mess with tests, as for now module suggests to not use this widget with translatable fields.

vladimir_kriukov’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
924 bytes

Drupal 10 patch