Introduction to Interface Extensions and Extension Points

User Interface Extensions (abbreviated as UIX) 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 (UIXP)
  • what we insert? - this is the UI Extension (UIX)

About Extension Points

Extensions Points (UIXP) 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 UIXs 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 UIX that uses the 'org.xwiki.platform.panels.Applications' extension point. UIXs are stored as standard XObjects, instances of XWiki.UIExtensionClass. For our UIX 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 UIX 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:
    {{velocity}}
    #foreach ($extension in $services.uix.getExtensions("my.new.extension.point"))
      $services.rendering.render($extension.execute(), 'xhtml/1.0')
    #end
    {{/velocity}}
  • Display the parameters:
    {{velocity}}
    #set ($extensions = $services.uix.getExtensions('my.new.extension.point', {'sortById' : ''}))
    #foreach ($extension in $extensions)
      $extension.parameters.label
    #end
    {{/velocity}}
  • Test the parameter for a particular value:
    {{velocity}}
    #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}}
     #end
    #end
    {{/velocity}}
Tags:
Created by Vincent Massol on 2017/09/05
   

Get Connected