Foros de discusión

Finding the context of a comment (MBDiscussion)

thumbnail
Alain Dresse, modificado hace 11 años.

Finding the context of a comment (MBDiscussion)

Junior Member Mensajes: 95 Fecha de incorporación: 18/07/11 Mensajes recientes
Hi,

As raised in LPS-14263, the asset publisher does not point to the correct blog entry for assets related to comments on the blog. This is also true for other comments (on a page, a document, a wiki page, ...).

I would like to use an asset publisher as a 'river' of assets created in a site, including comments. Does anybody know how to get the 'commented' asset from a MBDiscussion ?

Many thanks,
Alain

[EDITED: corrected the link to the Jira issue]
thumbnail
Alain Dresse, modificado hace 11 años.

RE: Finding the context of a comment (MBDiscussion) (Respuesta)

Junior Member Mensajes: 95 Fecha de incorporación: 18/07/11 Mensajes recientes
I found the solution, and thought I would share it:

The context of a comment (i.e. the item being commented) can be found directly in the MBMessage fields getClassName (the class name of the item being commented) and getClassPK(), the primary key of the item being commented.

Based on those, one could define a getURLViewInContext method in the MBDiscussionAssetRenderer to have a correct ViewInContext link :

	@Override
	public String getURLViewInContext(
		LiferayPortletRequest liferayPortletRequest,
		LiferayPortletResponse liferayPortletResponse,
		String noSuchEntryRedirect) {
		
		try {
			AssetRendererFactory rendererFactory = AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(_message.getClassName());
			AssetRenderer renderer = rendererFactory.getAssetRenderer(_message.getClassPK());
			return renderer.getURLViewInContext(liferayPortletRequest, liferayPortletResponse, noSuchEntryRedirect);
		} catch ( Exception e ) {
			e.printStackTrace();
		}
		
		return null;
	}


I hope this will help someone...