Extension Point Tutorial

Version 2.1 by Ecaterina Moraru (Valica) on 2014/02/26


Explain how to use existing extension points and how to create new ones based on examples.

Introduction to Interface Extensions and Extension Points

User Interface Extensions (abbreviated as UIX or IX) are used in order to provide a way to alter the content of existing interface elements. This functionality was added in version 4.2 and is documented in the UI Extension Module.

The main use case Interface Extensions try to fix is the need for applications (like Blog, Watchlist, etc.) to insert custom content in already existing interface components (like panels, menus, layout, etc.). 

Let's take an example: We developed an application called 'Hello World' and we want to provide a link to it inside the 'Applications' panel.
There are two questions that need to be answered: 

  • where we insert? - this is the Extension Point
  • what we insert? - this is the UI Extension (IX)

About Extension Points

Extensions Points specify where the new content is about to be inserted. Is like a hoof defined in the interface where Interface Extensions are gathered.
For our example, we need to know the extension point ID for the 'Applications' panel. That is 'org.xwiki.platform.panels.Applications'.

There is a list of available extension points where we can add functionality, but we can also manually define new extension points.

About Interface Extensions

All the IXs provided for a given Extension Point are displayed in that location.
For our example, if we want to add a new link in the 'Applications' panel, we need to create a new IX that uses the 'org.xwiki.platform.panels.Applications' extension point. IXs are stored as standard XObjects, instances of XWiki.UIExtensionClass. For our IX we will need to provide the label, target and icon parameters, in order to be properly displayed in the panel.

Read the documentation on how to add an IX inside the 'Applications' panel.

Adding your own Extension Point

Your UIExtension can define its own extension points, where other extensions can plug in. Here is an example of velocity code to include in your extension in order to make it an entry point for others:

  • Without parameters:
#foreach ($extension in $services.uix.getExtensions("my.new.extension.point"))
  $services.rendering.render($extension.execute(), 'xhtml/1.0')
  • Display the parameters:
#set ($extensions = $services.uix.getExtensions('my.new.extension.point', {'sortById' : ''}))
#foreach ($extension in $extensions)
  • Test the parameter for a particular value:
#foreach ($extension in $services.uix.getExtensions("my.new.extension.point"))
 #if ($extension.getParameters().get('parameter_name') == 'expected_value')

 {{html clean=false}}$services.rendering.render($extension.execute(), 'xhtml/1.0'){{/html}}

Get Connected