Tags - Fix in dotCMS Core in order to load Tag fields in contentlets
During Client tests after a dotCMS upgrade for a specific Client, a content page was unable to have tags rendered by Widget's Velocity code once the tags were updated; upon debugging, it was found that the contentlet asociated to the url-mapped page did not have loaded tags values on its "tags" field. This problem was fixed via hotfix mechanism but it may be fixed at dotCMS core level: dotCMS core's ESContentFactoryImpl is not always caching/returning contentlets with tags fields properly set.
Expected Behavior
dotCMS should successfully be able to load and render tags by following Widget's Velocity code:
<dt class="tag">Tags:</dt>
<dd>
#foreach($tag in $content.tags.split(","))
#set($tag = $tag.trim())
<a href="/resources/resource-library/listing.html?type=tag&search=$tag">$tag</a>#if($velocityHasNext), #end
#end
</dd>
Current Behavior
dotCMS is not currently able to render tags Widget's Velocity code at the moment widget is rendered because the associated contentlet field "$content.tags" is not loaded and populated with comma-separated tag values
Possible Solution
Following fix may be made in class ESContentFactoryImpl's convertFatContentletToContentlet method (package com.dotcms.content.elasticsearch.business), which may be incorporated as part of dotCMS's core (Added invocation to "con.setTags();"): https://github.com/dotCMS/core/blob/3.7.0/src/com/dotcms/content/elasticsearch/business/ESContentFactoryImpl.java#L280
public class ESContentFactoryImpl extends ContentletFactory {
...
public Contentlet convertFatContentletToContentlet(com.dotmarketing.portlets.contentlet.business.Contentlet fatty) throws ... {
Contentlet con = new Contentlet();
...
con.setTags();
...
return con;
}
...
}
Context
Reproduced during client tests on dotCMS cloud after migration/upgrade to dotCMS 3.7.0. Reported by client on ticket: https://my.dotcms.com/tickets/detail.dot?id=b05110d8-2ddf-484c-8ad8-4bd3fc549697
Your Environment
- dotCMS version used: 3.7.0.
- Browser Name and version: Any Browser
- Operating System and version: Amazon Linux
- Application Server and version: Apache Tomcat
- Database and version: Postgres
The fix for this issue may be borrowed from hot-fix at https://github.com/dotCMS/support/tree/master/hotfixes/hotfix-GIT-11117_v3.7.0. Also, the original Support ticket may be accessed at https://my.dotcms.com/tickets/detail.dot?id=b05110d8-2ddf-484c-8ad8-4bd3fc549697
PR (master-4.1): https://github.com/dotCMS/core/pull/11126
So, as discussed, I do not believe we want to store the tags on the content object itself and instead retrieve the lazily from the tagapi when needed.
This is not an issue. From the current revision on 4.1 the code specified by the client has issues.
In order for the current code to work, minor changes are required.
First, we need to verify how the variable $content is set. The correct way to fetch it is as follows:
#set($content = $dotcontent.find($ContentInode))
This code must be executed before calling the foreach statement.
Another issue found in the code is the split call. This call is not really required since the returned object is already a comma separated list.
The correct code must be defined as follows:
#foreach($tag in $content.tags) #set($tag = $tag.trim()) $tag#if($velocityHasNext), #end #end
Therefore the complete snippet will look like this: **
#foreach($tag in $content.tags) #set($tag = $tag.trim()) $tag#if($velocityHasNext), #end #end