Page tree
Skip to end of metadata
Go to start of metadata

This documentation is outdated


In this example i add a new column for the template name of the activated pages.

For a custom column in the inbox view we need 3 new classes:

  • CustomInbox.java
  • CustomInboxListModel.java
  • CustomInboxValueProvider.java

In the CustomInbox.java we add the additional column, give it a name, and tell Magnolia which information we want to be displayed in every entry.

CustomInbox.java
public class CustomInbox extends Inbox {
 
    Inbox inbox; //this is to prevent having a CustomInbox.html and use Inbox.html instead
 
    public CustomInbox(String name, HttpServletRequest request, HttpServletResponse response) {
        super(name, request, response);
        inbox = new Inbox(name, request, response); //this is to prevent having a CustomInbox.html and use Inbox.html instead
    }
 
    @Override
    public void configureList(ListControl list) {
        super.configureList(list);
 
        list.addGroupableField("template"); // make the column groupable by it's values
        list.addColumn(new ListColumn() {
            {
                setName("template");
                setLabel(MessagesManager.getMessages("info.magnolia.module.admininterface.messages").get("tree.web.template"));
                setWidth("150px");
            }
            @Override
            public Object getValue() {
                String uuid = "" + this.getListControl().getIteratorValue("uuid");
                String repository = "" + this.getListControl().getIteratorValue("repository");
                Content content = null;
                try {
                    content = MgnlContext.getSystemContext().getHierarchyManager(repository).getContentByUUID(uuid);
                } catch (RepositoryException e) {
                    return "-";
                }
                if(content == null)
                    return "-";
 
                String templateName = content.getTemplate();

                return StringUtils.isBlank(templateName) ? "-" : templateName;
            }
        });
    }
 
    @Override
    public ListModel getModel() {
        return new CustomInboxListModel(MgnlContext.getUser().getName());
    }
 
    @Override
    public String onRender() {
        return FreemarkerUtil.process(inbox); //this is to prevent having a CustomInbox.html and use Inbox.html instead
    }
}

Now we already have our custom column with the desired template name info in our inbox view. But as we want this column to be groupable by it's values we have to add another 2 classes.

CustomInboxListModel.java
public class CustomInboxListModel extends InboxListModel {
 

    public CustomInboxListModel(String userName) {
        super(userName);
 

        setValueProvider(new CustomInboxValueProvider()); //CustomInboxValueProvider provides values which are used for grouping the column. This class has yet to be created.
    }
 

}

Now create the following class:

CustomInboxValueProvider.java
public class CustomInboxValueProvider extends InboxValueProvider {

    @Override
    public Object getValue(String name, Object obj) {
        if(name.equals("template")) {
            String path = (String) getValue("path", obj);
            if (path != null) {
                return ContentUtil.getContent("website", path).getTemplate();
            }
        }

        return super.getValue(name, obj);
    }
}

The last step ist to edit the workflow module configuration. Under modules/workflow/pages/inbox set the property class to our newly created my.package.CustomInbox. Export the config and add it as a bootstrap file and you're done.

 

  • No labels

1 Comment

  1. Thanks! Useful example. Added this tip in official Workflow documentation.