close

Filter

loading table of contents...

Headless Server Developer Manual / Version 2110

Table Of Contents

4.8.3 Implementing Custom Link Composer

Custom link composers can be added by implementing the corresponding interface in a Spring bean: LinkComposer<?, ? extends GraphQLLink> for GraphQL links, and LinkComposer<?, ? extends UriLinkBuilder> for hyperlinks.

The latter kind of link composers need to be added for Content objects if you want to see hyperlinks within internal links in CoreMedia Rich Text markup which are described in Section 5.1.9, “Internal Links”. A sample LinkComposer for Content objects might look like this:

  @Bean
  public LinkComposer<Content, UriLinkBuilder> contentUriLinkComposer() {
    return content -> {
      String contentType = content.getType().getName();
      int numericContentId = IdHelper.parseContentId(content.getId());
      return Optional.of(new UriLinkBuilderImpl(
              UriComponentsBuilder.newInstance()
                      .scheme("coremedia")
                      .pathSegment(contentType, ""+numericContentId)
                      .build()));
    };
  }

Such a link composer will then generate URIs of the form coremedia:/contenttype/content id, for example, coremedia:/CMPicture/1726. Converting and rendering this URI as a clickable hyperlink (URL) is then the duty of the client. For example, in a React client using React Router, the URI may map to a corresponding route.

Link PostProcessors are not currently configured in the Headless Server. If required, post processors can be added to the configuration of the uriLinkComposer and/or graphQlLinkComposer beans.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.