Make your control panel custom portlet visible per site

Posted on by Charalampos Chrysikopoulos

Lets us assume we want to have an admin portlet in the content area in our site. We can do this by adding the following xml elements in the liferay-portlet.xml

...
<control-panel-entry-category>
content
</control-panel-entry-category>
<control-panel-entry-weight>1.5</control-panel-entry-weight>
...

But then we notice that this portlet exists also in the other sites. And we don't want that.

The solution to this problem is to add a class that implements the ControlPanelEntry interface.

This interface declares 3 methods that can allow you to restrict the visibility of the menu item:

        @Override
public boolean hasAccessPermission(PermissionChecker permissionChecker, Group group, Portlet portlet)
throws Exception {
 
if (MY_GROUP_ID == group.getGroupId()) {
return true;
}
return false;
}
 
@Override
public boolean isVisible(PermissionChecker permissionChecker, Portlet portlet)
throws Exception {
 
return true;
}
 
@Override
public boolean isVisible(Portlet portlet, String category, ThemeDisplay themeDisplay)
throws Exception {
 
if (MY_GROUP_ID == themeDisplay.getScopeGroupId()) {
return true;
}
 
return false;
}

This class must be also declared in liferay-portlet.xml like following

...
<control-panel-entry-category>
content
</control-panel-entry-category>
<control-panel-entry-weight>1.5</control-panel-entry-weight>
<control-panel-entry-class>your.entry.ClassHere</control-panel-entry-class>
...
This entry was posted in Liferay, Uncategorized and tagged Configuration, liferay 6.2 by Charalampos Chrysikopoulos