
Linking to web content on another page
Use case #
The portal has two pages: - title page with asset publisher portlet displaying list of latest content items (abstracts view) - news page, with asset publisher portlet displaying list of content items and other portlets allowing filtering by tags, categories etc.
We want that after clicking in title page on web contents title or 'read more' link, the user is redirected to the news page and the gets details view of the web content he ckicked.
The implementation #
Here is a patch that uses value of 'linked layout' asset publisher preference. The patch changes value of viewURL so that it links to the 'linked layout' page. The patch finds the first asset publisher portlet on that page and makes it display the clicked web content.
*** C:\projektai\lib\liferay\svn\6.0.6\portal-web\docroot\html\portlet\asset_publisher\display\abstracts.jsp 2011-02-02 12:37:49.687482300 +0200 --- C:\Temp\ap\abstracts.jsp 2011-03-24 10:13:58.310179800 +0200 *************** *** 54,59 **** --- 54,100 ---- String viewURLMessage = viewInContext ? assetRenderer.getViewInContextMessage() : "read-more-x-about-x"; viewURL = _checkViewURL(viewURL, currentURL, themeDisplay); + + // get linked page uuid + String linkToLayoutUuid = GetterUtil.getString( + preferences.getValue("portlet-setup-link-to-layout-uuid", null)); + + if(linkToLayoutUuid!=null && !"".equals(linkToLayoutUuid)) { + // get linked layout + Layout linkedLayout = null; + try { + linkedLayout = LayoutLocalServiceUtil.getLayoutByUuidAndGroupId( + linkToLayoutUuid, themeDisplay.getScopeGroupId()); + } + catch (PortalException pe) { + pe.printStackTrace(); + } + if (linkedLayout!=null) { + // find first AssetPublisher portlet on that layout + LayoutTypePortlet detailLayoutTypePortlet = (LayoutTypePortlet)linkedLayout.getLayoutType(); + List<Portlet> allPortlets = detailLayoutTypePortlet.getAllPortlets(); + String portletId = null; + for (Portlet p: allPortlets) { + if (PortletKeys.ASSET_PUBLISHER.equals(p.getRootPortletId())) { + portletId = PortletKeys.ASSET_PUBLISHER + PortletConstants.INSTANCE_SEPARATOR + p.getInstanceId(); + break; + } + } + if (portletId!=null) { + // make an url to this portlet + PortletURL portletURL = new PortletURLImpl(request, portletId , linkedLayout.getPlid(), PortletRequest.RENDER_PHASE); + + portletURL.setParameter("struts_action", "/asset_publisher/view_content"); + portletURL.setParameter("assetEntryId", String.valueOf(assetEntry.getEntryId())); + portletURL.setParameter("type", assetRendererFactory.getType()); + portletURL.setParameter("groupId", String.valueOf(assetRenderer.getGroupId())); + portletURL.setParameter("urlTitle", assetRenderer.getUrlTitle()); + + viewURL = portletURL.toString(); + viewURL = HttpUtil.setParameter(viewURL, "redirect", PortalUtil.getLayoutURL(linkedLayout,themeDisplay)); + } + } + } %> <c:if test="<%= show && assetRenderer.hasViewPermission(permissionChecker) %>">
I know, the 6.1 will have better implementation for this More flexible linking of web content to full page in Asset Publisher, http://issues.liferay.com/browse/LPS-15035. This is a simple patch against 6.0.6.