liferayliferay-6graphical-logo

How can we find the site logo for a Site programmatically


The site-logo appears from the theme using the code in portal_normal.vm:

<img alt="$logo_description" height="$site_logo_height" src="$site_logo" width="$site_logo_width" />

I want to know the value of the variable $site_logo in my custom plugin portlet.

I am showing all the sites in a list and want to show the different logos for public and private pages besides the site-name.

Any pointers would help.

Thanks


Solution

  • Basically, liferay shows image logo from ThemeDisplay object.

    I tried looking at ServicePreAction.java where themeDisplay object gets prepared, I found below things that would be helpful to you.

    Using code below you can get logourl for any Site's Public or Private pages which you can set to html image tag.

    LayoutSet siblingLayoutSet = LayoutSetLocalServiceUtil.getLayoutSet(
                                    groupId, isPrivatePages);
    
    if (siblingLayoutSet.isLogo()) {
        logoId = siblingLayoutSet.getLogoId();
    }
    
    StringBundler sb = new StringBundler(5);
    String imagePath=PortalUtil.getPathImage();
    sb.append(imagePath);
    sb.append("/layout_set_logo?img_id=");
    sb.append(logoId);
    sb.append("&t=");
    sb.append(WebServerServletTokenUtil.getToken(logoId));
    
    layoutSetLogo = sb.toString();