Creating a Plugin Configuration Page
To create a configuration page for a plugin that does not already have the
Configure icon displayed in the
Administration page, follow these steps:
- Register a
WebappServletextension type with aroleattribute set to config in yourplugin.xmlfile, as in the following example:<extension type="WebappServlet" role="config" class="com.ex.MyPluginConfigExt"/>
The
classattribute value should point to an extension of thePluginConfigExtensionclass. - When extending the
PluginConfigExtensionclass, consider the following notes:- Implement the
getOptionsFormmethod to return an HTML form and make sure that contains inputs with thenameattribute the same as the option you want to configure. - Implement the
getOptionsJsonmethod to return a JSON string that contains the options that you want to make available to the JavaScript code. They will be accessible in your plugin JavaScript code using thesync.options.PluginsOptions.getClientOption(optionName)method.Note
The JSON should only contain key values, where values are of the type string|number|boolean with no arrays or other objects.Tip
You should not include any sensitive information (e.g. OAuth secrets) in the options returned by this method. - Implement the
getPathmethod to return a non-empty string that represents the path for which this extension will be served.For example:
{webapp-context}/plugins-dispatcher/RESULT_OF_GETPATH - If you need to override the
initmethod, make sure you callsuper.init(). Otherwise, options will not be saved to disk and will be lost when you restart the application. - If you need to override any of the
doPut/doDeletemethods, make sure you call thesaveOptionsmethod at the end to save the options to disk. - If you need to override the
doGetmethod, make sure it responds with the result ofgetOptionsFormfor headerAccept=text/html, and with the result ofgetOptionsJsonwhen called with headerAccept=application/json. Use thegetOptionorgetDefaultOptionsmethods to access the current or default options.
Tip
For an implementation example, you can look atcom.oxygenxml.sdksamples.github.GithubPluginConfigExtensionin thewebapp-github-pluginproject. - Implement the
Configure icon is now displayed next to its name in the
Administration page.