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}}

Disabling some Extension Points

Until we fix XWIKI-13076, there is no 'clean' way to disable an UIX. 

In order to disable a page having an XWiki.UIExtensionClass object you can delete the page, delete the object, or use an invalid extension point ID. 

For example, if you would want to remove "User Index" from the Drawer, you should: 

  • Identify the extension point used by the Drawer. In our case this is org.xwiki.plaftorm.drawer.
  • Identify all the pages that use this extension point. For this, you can use Search to filter for documents that have Object Type = UI Extension. Make sure you have the "Display Hidden Pages" preference set to true, from the User Profile.
  • You will get a list of such pages, like Applications.WebHome, XWiki.UserIndexUIX, XWiki.DocumentIndexUIX, etc.
  • Go to the XWiki.UserIndexUIX page and from the Object Editor change the “Extension Point ID" value from org.xwiki.plaftorm.drawer ID to something else.
  • Save the page and the Drawer entry should disappear. 

In case you want to have conditional display for some entries, like showing "User Index" just for registered users, the ID needs to remain the valid one, but Velocity can be used to write conditions in the Extension Content property.

Tags:
Created by Vincent Massol on 2017/09/05
   

Get Connected