wcm.io Link Handler: How to add a custom Link Type

The Link Handler provides four default link types out of the box: Internal, Internal Cross-Context, External and Media. Sometimes you have the need to create a custom link type which provides:

  • A new link type is offered in the link type selection

  • Content editors can provide the parameters to build the Link URL via the link e (e.g. a Product ID for a link to a shopping system)

  • If possible, the parameters are validated within AEM to check if the link target exists

This article describes how to add a new link type. It is recommended to setup up you project with the wcm.io Maven Archetype for AEM.

 Instructions

  1. Add an implementation for a custom link type. This is a simple example building a link to Wikipedia:
    https://github.com/wcm-io/wcm-io-samples/blob/develop/bundles/core/src/main/java/io/wcm/samples/core/config/WikipediaLinkType.java

  2. Overwrite the list of link types in the project-specific LinkHandlerConfigImpl.java and add your custom link type:
    https://github.com/wcm-io/wcm-io-samples/blob/18d7dd9aa3b5efd207a04c923ca820ec3c1dd5ae/bundles/core/src/main/java/io/wcm/samples/core/config/impl/LinkHandlerConfigImpl.java#L47-L59

  3. Add a GraniteUI component backed by a JSP file (identified by the resource type provided with the getEditComponentResourceType() method):
    https://github.com/wcm-io/wcm-io-samples/blob/develop/bundles/core/src/main/webapp/app-root/components/global/linktype/wikipedia.json

  4. Provide some extra i18n keys for the author environment: