liferay-6.2liferay-hook

Get portlet type in Liferay 6.2 Hook


Inside Liferay 6.2 hook I want to know the portlet type(Asset Publisher/Web Content Display). Portlet name wont help me because User may have used custom title and in that case "Asset Publisher"/"Web Content Display" wont be accessible to me.

Exact hook file location where i want Portlet-type is: /html/portlet/portlet_css/view.jsp


Solution

  • Well without hooking other parts of Liferay you can't get it there (in java code). Portlet "Portlet CSS" is populated via javascript so there was apparently no need to send portletid as parameter.

    To get portletId you should also hook /html/js/liferay/look_and_feel.js

    autoLoad: false,
    showLoading: false,
    data: {
        p_l_id: themeDisplay.getPlid(),
        p_p_id: 113,
        p_p_state: EXCLUSIVE,
        doAsUserId: themeDisplay.getDoAsUserIdEncoded()
    },
    uri: themeDisplay.getPathMain() + '/portal/render_portlet'
    

    modify it to be something like this

    autoLoad: false,
    showLoading: false,
    data: {
        p_l_id: themeDisplay.getPlid(),
        p_p_id: 113,
        p_p_state: EXCLUSIVE,
        doAsUserId: themeDisplay.getDoAsUserIdEncoded(),
        _113_portletId: instance._portletId
    },
    uri: themeDisplay.getPathMain() + '/portal/render_portlet'
    

    comma and _113_portletId: instance._portletId were added.

    After that you can put in hooked /html/portlet/portlet_css/view.jsp

    String portletId = (String) renderRequest.getParameter("portletId");
    

    portletId for Asset publisher will be something like 101_INSTANCE_reKokSN3aDaL

    portletId for Web Content Display will be something like 56_INSTANCE_dxNxXuQ7ZuvB

    so you can test wether portletId starts with 101, 56, ...

    You can also get Portlet object with

    PortletLocalServiceUtil.getPortletById(portletId);
    

    UPDATE (answer to question in comment):

    This portlet was not intended for such use, once it loads it stays rendered in html and all modifications are made with javascript.

    When "Look and feel" is opened for first time after page load XHR request to server is made and "/html/portlet/portlet_css/view.jsp" is rendered. Second time (for another portlet on the same page), javascript prepares modal for another (or same) porlet, "/html/portlet/portlet_css/view.jsp" will not be rendered again.

    To force rerendering of "/html/portlet/portlet_css/view.jsp" modify again "/html/js/liferay/look_and_feel.js".

    after (in my source it is line 136)

    if (!content) {
        content = A.Node.create('<div class="loading-animation" />');
    } 
    

    add this

    if (instance._currentPopup) {
        A.one("#" + instance._currentPopup.get("id")).remove()
        instance._currentPopup = null;
    }
    

    It should be before

    if (!instance._currentPopup) {
        instance._currentPopup = Liferay.Util.Window.getWindow(
        ...
    

    Clear Liferay and browser cache.