Create a Custom Menu Item
Menu Plugin Overview
To allow users to trigger workflow actions from the CMS user interface, implement a module that includes the following components:
- Plugin Java class: A Wicket Java class. For standard plugins, you can often reuse existing code with minimal changes.
- Plugin HTML file: The markup file for the Wicket Java class.
- Plugin properties files: Resource bundles for translating UI labels.
- Icons: Images or sprites for the workflow action buttons.
You must also provide repository bootstrap configuration to specify when and where the plugin is available.
Folder Context Menu
The folder context menu is defined by the workflow category threepane. This menu is configured separately for admin, editor, and author roles.
The following example demonstrates how to add a simple "index" button to the folder context menu. When a user clicks this button, the system creates a document named "index" of a specified type.
Plugin Wicket Java Class: IndexWorkflowPlugin.java
Create the following file in your project: cms/src/main/java/com/example/IndexWorkflowPlugin.java.
package com.example; import org.apache.wicket.Component; import org.apache.wicket.model.StringResourceModel; import org.hippoecm.addon.workflow.StdWorkflow; import org.hippoecm.addon.workflow.WorkflowDescriptorModel; import org.hippoecm.frontend.plugin.IPluginContext; import org.hippoecm.frontend.plugin.config.IPluginConfig; import org.hippoecm.frontend.plugins.standards.icon.HippoIcon; import org.hippoecm.frontend.service.render.RenderPlugin; import org.hippoecm.frontend.skin.Icon; import org.hippoecm.repository.api.WorkflowDescriptor; import org.hippoecm.repository.standardworkflow.FolderWorkflow; public class IndexWorkflowPlugin extends RenderPlugin<WorkflowDescriptor> { public IndexWorkflowPlugin(IPluginContext context, IPluginConfig config) { super(context, config); add(new StdWorkflow<FolderWorkflow>("index", new StringResourceModel("index", this), (WorkflowDescriptorModel) getModel()) { @Override protected Component getIcon(final String id) { return HippoIcon.fromSprite(id, Icon.FILE); } @Override protected String execute(FolderWorkflow workflow) throws Exception { workflow.add("new-document", "myproject:index", "index"); return null; } }); } }
This class defines the IndexWorkflowPlugin, which adds a button to the CMS interface using Wicket. When a user clicks the button, the plugin executes a workflow action to create a new document.
Customizing the Plugin
To implement a more advanced workflow action, extend the provided example. The plugin uses Wicket's add method to register a button for the "index" workflow action. The anonymous subclass of StdWorkflow overrides getIcon to specify the button icon and execute to define the workflow logic. The StringResourceModel enables localization by referencing entries in the properties file.
Plugin Wicket HTML: IndexWorkflowPlugin.html
Place the markup file in the same package as the Java class. Store it under src/main/resources so Maven includes it automatically.
cms/src/main/resources/com/example/IndexWorkflowPlugin.html:
<html xmlns:wicket="http://wicket.apache.org/"> <wicket:panel> <div wicket:id="index">[ WORKFLOW ]</div> </wicket:panel> </html>
This Wicket HTML file defines a panel with a <div> element assigned the wicket ID "index". Wicket replaces the [ WORKFLOW ] placeholder with the rendered button.
Plugin Resource Bundle: IndexWorkflowPlugin.properties
Create a Java resource bundle to provide the label for the "index" button. Add the following file:
cms/src/main/resources/com/example/IndexWorkflowPlugin.properties:
index=Create index
To support additional languages, add localized properties files. For example, for Dutch:
cms/src/main/resources/com/example/IndexWorkflowPlugin_nl.properties:
index=Creeer index
Repository Configuration
Register the plugin in the appropriate plugin clusters for the context menu. The folder context menu is defined in the threepane workflow category at /hippo:configuration/hippo:workflows/threepane. Three nodes represent the clusters for different user roles:
folder-permissions/frontend:renderer(admins)folder-extended/frontend:renderer(editors)folder/frontend:renderer(authors)
To make the "Create index" action available to all roles, add a node of type frontend:plugin under each cluster. The node name is arbitrary; use "create-index" in this example.
/hippo:configuration/hippo:workflows/threepane/folder-permissions/frontend:renderer/create-index: jcr:primaryType: frontend:plugin plugin.class: com.example.IndexWorkflowPlugin wicket.id: ${item}
/hippo:configuration/hippo:workflows/threepane/folder-extended/frontend:renderer/create-index: jcr:primaryType: frontend:plugin plugin.class: com.example.IndexWorkflowPlugin wicket.id: ${item}
/hippo:configuration/hippo:workflows/threepane/folder/frontend:renderer/create-index: jcr:primaryType: frontend:plugin plugin.class: com.example.IndexWorkflowPlugin wicket.id: ${item}
Verifying the Plugin
Before testing, ensure that you have defined a document type named myproject:index in your project. Then, open the context menu for a folder in Content > Documents. The menu displays a "Create index" item at the end. Selecting this option creates a new document called "index".
Document Editor Menu
The document editor menu follows a similar approach to the folder context menu. The main differences are the workflow category and the workflow type.
The standard plugin cluster for the document editor menu is located at:
/hippo:configuration/hippo:workflows/default/handle/frontend:renderer
This menu uses the DocumentWorkflow type.
Submenu Placement
The document editor menu supports hierarchical structure. To control where your menu item appears, override the getSubMenu method in your plugin. The submenu named top is rendered in the menu bar. Use other names (such as document or publication) to add the item to an existing submenu.