[MGNLDEMO-159] Links created with RichTextField within Tours content app are not resolved Created: 30/Mar/16  Updated: 03/Jun/16  Resolved: 25/Apr/16

Status: Closed
Project: Magnolia Demo Projects
Component/s: tours-app
Affects Version/s: None
Fix Version/s: 0.12

Type: Bug Priority: Neutral
Reporter: Mercedes Iruela Assignee: Federico Grilli
Resolution: Fixed Votes: 2
Labels: support
Remaining Estimate: 0d
Time Spent: 1.5d
Original Estimate: Not Specified

Issue Links:
causality
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Release notes required:
Yes
Sprint: Basel 41
Story Points: 3

 Description   

If a 'Links to documents in the DAM' is included in a RichText Field in a content app, when this content is displayed as part of the page, the link is not rendered properly, the structure is like:

${link:{uuid:{795449d2-6c16-402e-9e8a-bbb101fe22bb},repository:{dam},path:{/tours/shark_brian_warrick_0824.JPG}}}

Same case, but rich text field in a component dialog is displayed properly.

Possible workaround: use method LinkUtil.convertLinksFromUUIDPattern()

This issue can be reproduced in travel-demo:

  1. Edit a tour in Tour App and introduce a 'Link to a DAM Document'.
  2. Publish the content
  3. Go to publicAuthor to see the tour information, the link format is not well formed, and DAM document cannot be downloaded.

Outcome
------------
The problem is due to the tour content (in the tours workspace) coming from a model and not from the node (in this case /travel/tour in website workspace) associated with the current rendering context. This basically means that the link resolution happening at https://git.magnolia-cms.com/projects/PLATFORM/repos/main/browse/magnolia-core/src/main/java/info/magnolia/jcr/util/ContentMap.java#222 does not happen for the model, hence the unresolved link. Afaics, there's no way for the Renderer to apply the same logic to the model, because that would mean knowing the internals of the model itself (in the specific case TourDetailModel has a getTour() method returning a Tour pojo which is retrieved from the tours workspace based on some request parameter).
All the above being said, it is the model responsibility in this case to resolve the links created with RTF component.

An alternative could be providing a templating function like resolveLinks(String) which could be used ad hoc directly in a template script. In our case at https://git.magnolia-cms.com/projects/MODULES/repos/demo-projects/browse/community/magnolia-travel-tours/src/main/resources/tours/templates/components/tourDetail.ftl#118 e.g.

<div class="body">${somefn.resolveLinks(tour.body)!}</div>

Generated at Mon Feb 12 05:16:54 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.