Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Hiding "My Sites" Menu in Docbar in Liferay

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 2.15k
    Comment on it

    You can hide the "My Sites" menu from Liferay Docbar by creating hook. In my example i am hidding the menu option for all the users except those whose role is Administrator. You need to Hook the html/taglib/ui/my_sites/page.jsp

    Add the following code to check whether the logged in user is administrator role.

    boolean isAdminUser=permissionChecker.isOmniadmin();
    

    Hence if the logged in user is Administrator we are showing the My Sites menu else hidding it. I added extra condition of isAdminUser in following code for same.

    <c:if test="<%= !mySiteGroups.isEmpty() && isAdminUser %>">
    

    Following is the code snippet from page.jsp

    <%@ include file="/html/taglib/init.jsp" %>
    
    <%
    String[] classNames = (String[])request.getAttribute("liferay-ui:my_sites:classNames");
    String cssClass = GetterUtil.getString((String)request.getAttribute("liferay-ui:my_sites:cssClass"));
    boolean includeControlPanel = GetterUtil.getBoolean((String)request.getAttribute("liferay-ui:my_sites:includeControlPanel"));
    int max = GetterUtil.getInteger((String)request.getAttribute("liferay-ui:my_sites:max"));
    
    if (max <= 0) {
        max = PropsValues.MY_SITES_MAX_ELEMENTS;
    }
    
    List<Group> mySiteGroups = user.getMySiteGroups(classNames, includeControlPanel, max);
    boolean isAdminUser=permissionChecker.isOmniadmin();
    System.out.println("\n\n\n\n\n\n  isAdminUser \n\n\n\n\n\n"+isAdminUser);
    %>
    
    <c:if test="<%= !mySiteGroups.isEmpty() && isAdminUser %>">
        <ul class="taglib-my-sites <%= cssClass %>">
    
            <%
            PortletURL portletURL = new PortletURLImpl(request, PortletKeys.SITE_REDIRECTOR, plid, PortletRequest.ACTION_PHASE);
    
            portletURL.setParameter("struts_action", "/my_sites/view");
            portletURL.setPortletMode(PortletMode.VIEW);
            portletURL.setWindowState(WindowState.NORMAL);
    
            for (Group mySiteGroup : mySiteGroups) {
                String escapedSiteName = HtmlUtil.escape(mySiteGroup.getName());
    
                boolean showPublicSite = mySiteGroup.isShowSite(permissionChecker, false);
                boolean showPrivateSite = mySiteGroup.isShowSite(permissionChecker, true);
            %>
                    .
                    .
                    .
                    .
                    .
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: