TranslationHelper not working for EditorialContentEntityBase entities

Created on 29 September 2023, about 1 year ago
Updated 2 November 2023, about 1 year ago

Problem/Motivation

Using storage entities inside IEF forms on a multilingual site does not work.

When translating the parent node, the inline storage entity is not translated.

I've traced the issue in Drupal\inline_entity_form\TranslationHelper::prepareEntity().

The wrapper condition excludes storage entities which extend Drupal\Core\Entity\EditorialContentEntityBase thus not of the expected ContentEntityTypeInterface type.

Steps to reproduce

  • A site with at least 2 languages
  • Create a Storage Type
  • Create a Node Type
  • Add a reference field on the Node Type targetting the Storage type
  • Use either the Inline Entity Form simple or complex in the node form display
  • Create a node and add an inline storage entity
  • Translate the node and update the inline storage entity

Result: the inline storage entity is not translated - but you're editing the original language.

Proposed resolution

Update the wrapper condition to accept a broader scope of Content entity:

  use Drupal\Core\Entity\ContentEntityTypeInterface;
  // ...
  public static function prepareEntity(EntityInterface $entity, FormStateInterface $form_state) {
    if ($entity instanceof ContentEntityTypeInterface) {
      $form_langcode = $form_state->get('langcode');
      // ...

By:

  use Drupal\Core\Entity\ContentEntityInterface;
  // ...
  public static function prepareEntity(EntityInterface $entity, FormStateInterface $form_state) {
    if ($entity instanceof ContentEntityInterface) {
      $form_langcode = $form_state->get('langcode');
      // ...

Remaining tasks

Review code.

πŸ› Bug report
Status

Postponed: needs info

Version

2.0

Component

Code

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @matthieuscarset
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update about 1 year ago
    Composer require failure
  • @matthieuscarset opened merge request.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update about 1 year ago
    Composer require failure
  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul

    In version 1 of IEF, TranslationHelper worked for storage entities. That's because it didn't provide the conditional logic that this patch corrects.

    While the patch addresses the specific issue it found for TranslationHelper, there is need to fix more of inline entity form in order for a content creator / editing to manage content that uses both inline entity form and storage entities.

    The same issue and fix that this issue is talking about was reported in πŸ› Unable to update micro-content entities via Inline Entity Form Active . I believe we need the same kind of fix there.

    When thinking about where to put that logic, I was wondering if expanding this patch to include the additional fix would be good.

    Should I expand the scope of this issue / patch?

  • πŸ‡ΊπŸ‡ΈUnited States cosmicdreams Minneapolis/St. Paul

    After this change there is only more additional use of ContentEntityTypeInterface but it appears to be in logic that hides the revision log for revisionable content types:

    EntityInlineForm::entityForm line 211

    // Hide the log message field for revisionable entity types. It cannot be
        // disabled in UI and does not make sense in inline entity form context.
        if (($this->entityType instanceof ContentEntityTypeInterface)) {
          if ($log_message_key = $this->entityType->getRevisionMetadataKey('revision_log_message')) {
            // Safely restrict access. Entity type cacheability already set.
            RenderArray::alter($entity_form[$log_message_key])->restrictAccess(FALSE, NULL);
          }
        }
    

    Should we discuss if this should be modified to target ContentEntityInterface instead?

  • Status changed to Postponed: needs info about 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine podarok Ukraine

    Would be great to hear more from @matthieuscarseta about current state of the MR

Production build 0.71.5 2024