Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export the raw value of rich text fields #49

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions news/48.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Export the raw value of rich text fields, instead of the transformed output.
This fixes internal links in Classic UI based distributions.
@mauritsvanrees
1 change: 1 addition & 0 deletions src/plone/exportimport/serializers/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<adapter factory=".blocks.ExportImportBlocksSerializer" />
<adapter factory=".fields.CollectionFieldSerializer" />
<adapter factory=".fields.ChoiceFieldSerializer" />
<adapter factory=".fields.ExportImportRichTextSerializer" />
</configure>
15 changes: 15 additions & 0 deletions src/plone/exportimport/serializers/fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from plone.app.textfield.interfaces import IRichText
from plone.app.textfield.interfaces import IRichTextValue
from plone.dexterity.interfaces import IDexterityContent
from plone.exportimport.interfaces import IExportImportRequestMarker
from plone.restapi.interfaces import IFieldSerializer
Expand Down Expand Up @@ -76,3 +78,16 @@ def __call__(self):
self.context,
)
return json_compatible(value)


@adapter(IRichText, IDexterityContent, IExportImportRequestMarker)
class ExportImportRichTextSerializer(DefaultFieldSerializer):
def __call__(self):
value = self.get_value()
if value is None or not IRichTextValue.providedBy(value):
return json_compatible(value, self.context)
return {
"data": json_compatible(value.raw),
"content-type": json_compatible(value.mimeType),
"encoding": json_compatible(value.encoding),
}