Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Summary
An English node cannot be translated to German if a field using IEF references Finnish content (and that reference has no English translation).
Reproducible with a fresh site on https://simplytest.me:
- Drupal Core 8.3.7
- Inline Entity Form 8.x-1.0-beta1
Preparation:
Site:
- Install standard site with English
- Install Inline Entity Form module at /admin/modules
- Install Content Translation module at /admin/modules (enables Language module)
- Add German and Finnish at /admin/config/regional/language/add
- Change error display: All messages, with backtrace information at /admin/config/development/logging
Content type:
- Enable translation for Article and "Show language selector on create and edit pages" at /admin/structure/types/manage/article
- Add a new field to Reference to Content, called "Card list" at /admin/structure/types/manage/article/fields/add-field and reference Articles
- Manage the form display at /admin/structure/types/manage/article/form-display and select "Inline Entity Form - Complex" for "Card list", then "Allow users to add existing nodes"
Content:
- Create "Finnish article to reference" at /node/add/article and save as Finnish
- Create "English article that references a Finnish one" at /node/add/article, add the existing Finnish node and save as English
To reproduce:
- Open "English article that references a Finnish one"
- Click the Translate tab
- Click "Add" next to German
Expected result:
Form opens to edit and save translation
Actual result:
The website encountered an unexpected error. Please try again later.
InvalidArgumentException: Invalid translation language (en) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (line 783 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Drupal\inline_entity_form\TranslationHelper::prepareEntity(Object, Object) (Line: 338)
Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormBase->prepareFormState(Object, Object, 1) (Line: 215)
Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex->formElement(Object, 0, Array, Array, Object) (Line: 322)
Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 85)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object, NULL) (Line: 532)
Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormBase->form(Object, Array, Object) (Line: 168)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 122)
Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 98)
Drupal\node\NodeForm->form(Array, Object) (Line: 115)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('node_article_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'default', Array) (Line: 350)
Drupal\content_translation\Controller\ContentTranslationController->add(Object, Object, Object, 'node')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
02:28:25 drupal 8.3.7 ✘
The backtrace points the finger at inline_entity_form.
Additional notes:
- Change the Card list to use Autocomplete instead of IEF at /admin/structure/types/manage/article/form-display
- You can now translate to German.
Comment | File | Size | Author |
---|---|---|---|
#2 | inline_entity_form-add_source_lang_to_ref-2908780-2-8.x.patch | 765 bytes | jsdix |
Comments
Comment #2
jsdix CreditAttribution: jsdix at Acquia commentedI'm working on a project where we are also running into this when translating content that use entity_inline_form elements. It appears that if the referenced entity does not have a translation matching the source language of the parent, that is when the fatal error is thrown.
should probably be
I've created a patch which solves the issue.
Comment #3
jsdix CreditAttribution: jsdix at Acquia commentedComment #4
jsdix CreditAttribution: jsdix at Acquia commentedComment #5
vasyl.kletsko CreditAttribution: vasyl.kletsko commentedThanks jsdix for providing a patch, it fixes this bug.
Comment #7
bojanz CreditAttribution: bojanz at Centarro commentedThanks!