M5: Create a custom action and send a message to the pulse

Actions already existed in previous versions of Magnolia, but they are now magnified by their ease of integration in Magnolia’s new version, augmented with a very nice framework with nice communication and user notification possibilities.

The Pulse is magnolia’s new inbox, it can be used for many purposes, but is mainly designed as the system’s intercommunication’s center. The Pulse allows different users with different authorizations or roles to communicate and collaborate together.

What I will try to show in this post is how you easily can send a message to the pulse by implementing a custom action.
We suppose you already have a module, a webapp and the Magnolia CMS CE 5.0 bundle.
In the actions node of our app configuration, the app where we want to have the action enabled, we add the following configuration.

Click on the image to get readable values

  • availability/access/roles defines the roles for which this button or action should be accessible.
  • appName will be the name of our app in which the action should be defined
  • class will be our action definition class, not the action itself, I will come back on this later.

I won’t explain the other values now.Let’s concentrate on the action class which is the main topic of this post.

As I already wrote, the class actually defines the action’s definition class, not the implemented action itself, this because the definition class will act as a parameter object for our action itself:

public class RequestForActivationActionDefinition extends ConfiguredActionDefinition {

    public RequestForActivationActionDefinition() {

As soon as the class is available on the classpath and defined in the app’s config, this definition class will be instantiated.
The action however will only be instantiated and executed only if the corresponding button is clicked.
So let’s explain our action class.

public class RequestForActivationAction extends AbstractAction<RequestForActivationActionDefinition> {

    private final Shell shell;
    private final SubAppContext subAppContext;

    public RequestForActivationAction(RequestForActivationActionDefinition definition,SubAppContext subAppContext,  Shell shell) {
        this.shell = shell;
        this.subAppContext = subAppContext;

    public void execute() throws ActionExecutionException {
        MessageStyleTypeEnum messageStyleType;
        messageStyleType = MessageStyleTypeEnum.INFO;
        Message message = new Message();
        message.setMessage("User "+MgnlContext.getUser().getName()+ " would like to activate the following ");
        message.setSubject("request for activation");
        //give it the messageView we want to display on opening the message
        message.put(Message.MESSAGE_VIEW, "addresto:restoView");
        //we need the location to travel back to the contentview and approve or reject
        subAppContext.getAppContext().sendUserMessage("superuser", message);
        shell.openNotification(messageStyleType, true, "Your request for activation has been sent !");

To send a message we need the appcontext so we inject the actual SubAppContext which will give us the appcontext, to show a notification we use the shell, which will allow us to show notifications to users.
We as well would like to open a specific messageView when the superuser opens the message with specific actions, before we however will have to declare it ( you can copy the admincentral messageView structure under you app and rename it to the view you want).

Finally we want our superuser to travel back to the location from which we send the message so we will add an extra “location” param in the message’s map.
To travel back to the location, you can create another custom action, add it in your messageView, inject the current Message and the LocationController in it and use this last one to travel back to the source of this message.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: