We are using DXA 2.0 (Java) and can see if we embed images in RTF fields that the RTF contains the embedded Image entity as part of the set of fragments generated for the RTF. However if we link to another type of multimedia component (for example a PDF) we do not see an embedded entity (in this case Download), just the resolved <a>
anchor link. In our case we want to rewrite the link to the download to include the download size and icon for filetype - is this somehow possible?
-
Wouldn’t you just regex the rtf in the manager/business logic class/helper and rewrite it there or in the view? Or are you looking for a less strenuous option?– Nickoli RoussakovApr 4, 2018 at 13:06
-
1We would like to do exactly that - the problem is that in the Model/View there is no longer any information in the link other than the published binary URL, so we cannot get the filesize. If there was an embedded entity then it would be possible– Will PriceApr 5, 2018 at 8:52
2 Answers
In DXA 2.0 (R2 Data Model), Rich Text Field processing is done on CM-side: see method DataModelBuilder.BuildRichTextModel
https://github.com/sdl/dxa-content-management/blob/master/Sdl.Web.Tridion.Templates.R2/Data/DataModelBuilder.cs
Indeed, only MM Component Links for img
tags are "expanded" by the Default Model Builder.
If you want to customize the Rich Text Field processing, you can do a few things:
- Create your own Data Model Builder (a class which implements
IEntityModelDataBuilder
and/orIPageModelDataBuilder
) and add that to the Data Model Builder Pipeline in order to find and post-process any Rich Text Data. See https://docs.sdl.com/LiveContent/content/en-US/SDL%20DXA-v10/GUID-1C3C1401-D38A-4C23-8B6D-7735C068F9B0 - Create your own TBB to post-process the Rich Text Data. This is a bit easier to do (more isolated), but does require you to deserialize and serialize the R2 Data Model in your TBB.
- Associate your linked MM Component's Schema with the "Generate Data Presentation" CT. This will ensure that your linked MM Component's Data will get published separately as DCP. This will allow you to retrieve the linked MM Component dynamically in your Web App (e.g. in a DXA Model Builder) and do the post-processing there.
-
1Thats clear Rick - there is a 4th approach, and this is to adapt DXA to make it more configurable which linked items in RTF fields get expanded, only processing img tags is quite limited. I will have a go at this and put a Pull Request in. Apr 6, 2018 at 8:01
-
We solved this by making the DXA have a more generic approach to embedding entities in Rich Text fields. Required for this was:
Updates to DXA 2.0 Template logic (see pull request):
- New TBB parameter to specify a list of schema names for which to replace links in Rich Text fields with embedded entities
- Update to logic in templates to process this parameter into the DataModelBuilderSettings
- Update the DataModelBuilder to extend the logic to process img tags to create entities any item with an xlink:href
Update to Java Web Application (see pull request):
- Made
RichTextDataConverter.convert
method more generic to also handle non MediaItem models
Update to .NET Web Application (see pull request):
- Made
DefaultModelBuilder.MapRichText
method more generic to also handle non MediaItem models