If Experience Builder field is not translatable the dynamic source properties do not use the translated entity field value

Created on 20 June 2024, 5 months ago
Updated 24 June 2024, 5 months ago

Problem/Motivation

Follow-up to πŸ“Œ Allow Experience Builder fields to support Asymmetric and Symmetric translations Needs review where it was found
If Experience Builder field is not translatable but it is on a translatable entity the dynamic source properties do not use the translated entity field values. In #3454257 I just confirmed this with the title field but we could confirm that is the case with other fields.

I think the expected behavior would be that if you left the XB field untranslatable but used dynamic entity properties when you viewed the translated version of the entity it would show you the translated entity field values.

An example of this would be if a site had a translatable article content type. They may want to use XB to arrange the output of the fields differently for different articles but components may only display field values from the actual entity so there is not need to make the XB field itself translatable. They would just expected the correct field values for the correct translation to show.

If XB would be used in this way it would much simpler for the content editor to not to have the XB field be translatable even for the props column, especially for sites with many languages. Because if props was translatable then if 1 component use the dynamic property entity->title but then wanted to change it instead use the dynamic text property entity->field_catch_property then they would not have to change it in all languages. If the props column was translatable then they would have change this in all languages

Steps to reproduce

Proposed resolution

Make dynamic entity properties used the translated values of the entity for the current translation even if the XB is not translatable.

Remaining tasks

  1. Determine current behavior of other cases when the XB field is not translated but is on translated entity.

    For example if you using a static property of a media entity reference value if you are viewing the non-default French translation of a article and the media entity you are referencing also has French translation will it display the French version?

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: outdated

Component

Data model

Created by

πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

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

Comments & Activities

  • Issue created by @tedbow
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • Status changed to Postponed 5 months ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    Ok I think figure out why this happens.

    1. \Drupal\Core\Entity\ContentEntityBase::get() calls \Drupal\Core\Entity\ContentEntityBase::getTranslatedField
    2. getTranslatedField has
      if (!$default && !$definition->isTranslatable()) {
              if (!isset($this->fields[$name][LanguageInterface::LANGCODE_DEFAULT])) {
                $this->fields[$name][LanguageInterface::LANGCODE_DEFAULT] = $this->getTranslatedField($name, LanguageInterface::LANGCODE_DEFAULT);
              }
              $this->fields[$name][$langcode] = &$this->fields[$name][LanguageInterface::LANGCODE_DEFAULT];
            }
            else {
      

      So in the case the XB field is not translated it do a recursive call to getTranslatedField() but his time using LanguageInterface::LANGCODE_DEFAULT

    3. In the recursive call to getTranslatedField() then this is called
      $field = \Drupal::service('plugin.manager.field.field_type')->createFieldItemList($this->getTranslation($langcode), $name, $value);
      

      So $this->getTranslation($langcode) means the field item list will be created with the default, LanguageInterface::LANGCODE_DEFAULT translation, even though the entity that had the original call to \Drupal\Core\Entity\ContentEntityBase::get() in step above could have been the translation of another language.

    I am not sure why this happens but it seems very intentional. Will investigate further.

  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    Ok, this change was made in #2513094: ContentEntityBase::getTranslatedField and ContentEntityBase::__clone break field reference to parent entity β†’

    $field = \Drupal::service('plugin.manager.field.field_type')->createFieldItemList($this, $name, $value);
    

    was changed to

    $field = \Drupal::service('plugin.manager.field.field_type')->createFieldItemList($this->getTranslation($langcode), $name, $value);
    

    I will read up that issue. But presumably there was a good reason to need the translation instead of the original entity object.

  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    I think I have found a solution in πŸ“Œ Allow Experience Builder fields to support Asymmetric and Symmetric translations Needs review . If that solution does not work we can re-open this

  • Status changed to Closed: outdated 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA
Production build 0.71.5 2024