Uploaded image for project: 'Magnolia REST Framework'
  1. Magnolia REST Framework
  2. MGNLREST-265

Support resolve links in richTextField via NodeWriter

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Neutral Neutral
    • None
    • 2.2.1
    • delivery
    • mgnl-6.2.2
    • Yes
    • Yes
    • Yes

      reproduce steps

      1. create a text component

      form:
        properties:
          text:
            label: Text
            $type: richTextField
      

      2.
      add the component to a page and maintain a link

      3.
      Do a request against the delivery API:  http://localhost:8080/author/.rest/delivery/pages/v1/demo-content

      The response is:

      	"main": {
      		"@name": "main",
      		"@path": "/demo-content/main",
      		"@id": "ceecf6c7-8a5c-48e1-a5d8-2dda9e5a0dfe",
      		"@nodeType": "mgnl:area",
      		"0": {
      			"@name": "0",
      			"@path": "/demo-content/main/0",
      			"@id": "86c4e0a6-159d-4911-b589-4f6e2888e15c",
      			"@nodeType": "mgnl:component",
      			"text": "<p><a href=\"${link:{uuid:{943d6ee7-f6a5-4be0-9fb9-415b59b95523},repository:{website},path:{/demo-content/inhlatsseite}}}\">test</a></p>\n",
      			"mgnl:template": "test:components/text",
      			"@nodes": []
      		},
      		"@nodes": ["0"]
      	}
      

      expected result

      I would expect a real page link. 

      actual result

      described above

      implementation notes

      The functionality I added is from the ContentMap. For freemarker, the links ware resolved there.
      Would be better if we can have a flag in the endpoint definition for this function, true by default. Things like resolve references taking a number of depth.

      Customer notes

      Possible Solution:

      private String getValueString(Value value) throws RepositoryException {
              switch (value.getType()) {
              case PropertyType.BINARY:
                  return getBinaryString(value);
              case PropertyType.DECIMAL:
                  return String.valueOf(value.getDecimal());
              case PropertyType.NAME:
              case PropertyType.URI:
              case PropertyType.DATE:
                  return value.getString();
              default:
                  return getStringValue(value);
              }
          }
      
          public String getStringValue(final Value value) {
              String result = PropertyUtil.getValueString(value);
              if (LinkUtil.UUID_PATTERN.matcher(result).find()) {
                  try {
                      result = info.magnolia.link.LinkUtil.convertLinksFromUUIDPattern(result);
                  } catch (LinkException e) {
                      LOGGER.warn("Failed to parse links with from {}", result, e);
                  }
              }
      
              return result;
          }
      

        Acceptance criteria

              Unassigned Unassigned
              viet.nguyen Viet Nguyen
              DeveloperX
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:

                  Task DoD