Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc start='2'/}}
3 {{/box}}
5 == Introduction to Interface Extensions and Extension Points ==
7 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>>extensions:Extension.UIExtension Module]].
9 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.).
11 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.
12 There are two questions that need to be answered:
14 * where we insert? - this is the Extension Point (UIXP)
15 * what we insert? - this is the UI Extension (UIX)
17 === About Extension Points ===
19 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.
20 For our example, we need to know the extension point ID for the 'Applications' panel. That is '##org.xwiki.platform.panels.Applications##'.
22 There is a list of [[available extension points>>platform:ExtensionPoint.WebHome]] where we can add functionality, but we can also manually define new extension points.
24 === About Interface Extensions ===
26 All the UIXs provided for a given Extension Point are displayed in that location.
27 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.
29 Read the documentation on [[how to add an UIX>>extensions:Extension.UIExtension Module||anchor="HWritingasimpleUIExtension"]] inside the 'Applications' panel.
31 == Adding your own Extension Point ==
33 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:
35 * Without parameters:(((
36 {{code language="velocity"}}
37 {{velocity}}
38 #foreach ($extension in $services.uix.getExtensions(""))
39 $services.rendering.render($extension.execute(), 'xhtml/1.0')
40 #end
41 {{/velocity}}
42 {{/code}}
43 )))
44 * Display the parameters:(((
45 {{code language="velocity"}}
46 {{velocity}}
47 #set ($extensions = $services.uix.getExtensions('', {'sortById' : ''}))
48 #foreach ($extension in $extensions)
49 $extension.parameters.label
50 #end
51 {{/velocity}}
52 {{/code}}
53 )))
54 * Test the parameter for a particular value:(((
55 {{code language="velocity"}}
56 {{velocity}}
57 #foreach ($extension in $services.uix.getExtensions(""))
58 #if ($extension.getParameters().get('parameter_name') == 'expected_value')
60 {{html clean=false}}$services.rendering.render($extension.execute(), 'xhtml/1.0'){{/html}}
61 #end
62 #end
63 {{/velocity}}
64 {{/code}}
65 )))
67 == Disabling some Extension Points ==
69 Until we fix [[XWIKI-13076>>]], there is no 'clean' way to disable an UIX.
71 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.
73 For example, if you would want to remove "User Index" from the Drawer, you should:
75 * Identify the extension point used by the [[Drawer>>extensions:Extension.Flamingo Skin||anchor="HDrawer"]]. In our case this is ##[[org.xwiki.plaftorm.drawer>>xwiki:Documentation.DevGuide.ExtensionPoint.DrawerItem]]##.
76 * Identify all the pages that use this extension point. For this, you can use [[Search>>extensions:Extension.Solr Search Application]] 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>>extensions:Extension.User Profile Application||anchor="HEditPreferences"]].
77 * You will get a list of such pages, like ##Applications.WebHome##, ##XWiki.UserIndexUIX##, ##XWiki.DocumentIndexUIX##, etc.
78 * Go to the ##XWiki.UserIndexUIX## page and from the [[Object Editor>>xwiki:Documentation.UserGuide.Features.PageEditing||anchor="HObjectseditingmode"]] change the “Extension Point ID" value from ##org.xwiki.plaftorm.drawer## ID to something else.
79 * Save the page and the Drawer entry should disappear.
81 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>>extensions:Extension.Velocity Macro]] can be used to write conditions in the ##Extension Content## property.

Get Connected