Skip to content

Rich Text field created without locale specification #338

@lamasfoker

Description

@lamasfoker

Steps to reproduce

  1. Create a Contentful Space with 2 locales: English (default) and Italian;
  2. Create an Entry Model "Blog Post" with a Body field of type Rich Text;
  3. Create a "Blog Post" Entry with an Image in the Body field, the same image for the English and Italian Body fields;
  4. The Image Asset has both title and description filled in both languages;
  5. Try to render the Blog Post Entry in the not default language (Italian)

Expected Result

The title of the image present in the Body of the Blog Post should be in Italian

Actual Result

The title of the image present in the Body of the Blog Post is in English

Considerations

Take a look to this issue patched on contentful/rich-text.php repository. You can patch this module like this:

diff --git a/src/Mapper/Entry.php b/src/Mapper/Entry.php
index d539fe4..9018a7e 100644
--- a/src/Mapper/Entry.php
+++ b/src/Mapper/Entry.php
@@ -98,7 +98,8 @@ class Entry extends BaseTaggedMapper
                 $fields[$name][$locale] = $this->formatValue(
                     $field->getType(),
                     $value,
-                    $field->getItemsType()
+                    $field->getItemsType(),
+                    $locale
                 );
             }
         }
@@ -146,7 +147,7 @@ class Entry extends BaseTaggedMapper
      *
      * @return mixed
      */
-    private function formatValue(string $type, $value, string $itemsType = null)
+    private function formatValue(string $type, $value, string $itemsType = null, string $locale = null)
     {
         // Certain fields are already built as objects (Location, Link, DateTimeImmutable)
         // if the entry has already been built partially.
@@ -161,8 +162,8 @@ class Entry extends BaseTaggedMapper

         switch ($type) {
             case 'Array':
-                return array_map(function ($value) use ($itemsType) {
-                    return $this->formatValue((string) $itemsType, $value);
+                return array_map(function ($value) use ($itemsType, $locale) {
+                    return $this->formatValue((string) $itemsType, $value, $locale);
                 }, $value);
             case 'Date':
                 return new DateTimeImmutable($value, new \DateTimeZone('UTC'));
@@ -171,7 +172,7 @@ class Entry extends BaseTaggedMapper
             case 'Location':
                 return new Location($value['lat'], $value['lon']);
             case 'RichText':
-                return $this->richTextParser->parse($value);
+                return $this->richTextParser->parseLocalized($value, $locale);
             default:
                 return $value;
         }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions