Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

AEM 6550 - Move Render Condition for Assets with References | AEM Community Blog Seeding

Avatar

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,127 likes

Total Posts

6,116 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,127 likes

Total Posts

6,116 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile
kautuk_sahni
Community Manager

19-08-2020

BlogImage.jpg

AEM 6550 - Move Render Condition for Assets with References by Sreekanth Choudry Nalabotu

Abstract

A sample render condition to show Move action bar button in Asset console only if one (or some) of the assets in a folder have references (say they are part of a Dynamic Media Image Set)

1) Overlay /libs/dam/gui/content/assets/jcr:content/actions/selection/moveasset/granite:rendercondition into /apps/dam/gui/content/assets/jcr:content/actions/selection/moveasset/granite:rendercondition

2) Set /apps/dam/gui/content/assets/jcr:content/actions/selection/moveasset/granite:rendercondition@sling:resourceType to /apps/eaem-move-references-rendercondition

3) Create the Render condition /apps/eaem-move-references-rendercondition/eaem-move-references-rendercondition.jsp with following code

<%@page session="false"
import="com.adobe.granite.ui.components.ComponentHelper,
com.adobe.granite.ui.components.Config,
org.apache.sling.api.resource.Resource,
org.apache.sling.api.resource.ValueMap,
com.adobe.granite.ui.components.rendercondition.RenderCondition,
com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition,
javax.jcr.Node,
com.day.cq.dam.commons.util.UIHelper,
com.day.cq.dam.api.DamConstants" %>
<%@ page import="javax.jcr.Session" %>
<%@ page import="javax.jcr.query.QueryManager" %>
<%@ page import="javax.jcr.query.Query" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="javax.jcr.NodeIterator" %>
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.2" %>
<%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %>




<%

ComponentHelper cmp = new ComponentHelper(pageContext);
Config cfg = cmp.getConfig();
String path = cmp.getExpressionHelper().getString(cfg.get("path", String.class));
Resource contentRes = null;

if (path != null) {
contentRes = slingRequest.getResourceResolver().getResource(path);
} else {
contentRes = UIHelper.getCurrentSuffixResource(slingRequest);
}

if (contentRes == null) {
return;
}

Iterator itr = contentRes.listChildren();
StringBuilder strBuilder = new StringBuilder();

strBuilder.append("//element(*, nt:unstructured)[");

while(itr.hasNext()){
strBuilder.append("@sling:resource = '").append(itr.next().getPath()).append("' or");
}

String queryStmt = strBuilder.toString();

queryStmt = queryStmt.substring(0, queryStmt.lastIndexOf("or")) + "]";

Session session = resourceResolver.adaptTo(Session.class);
QueryManager qm = session.getWorkspace().getQueryManager();

Query query = qm.createQuery(queryStmt, Query.XPATH);

NodeIterator results = query.execute().getNodes();

boolean showMove = results.hasNext();

if(showMove){
%>

<%
}else{
request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(false));
}
%>

Read Full Blog

AEM 6550 - Move Render Condition for Assets with References

Q&A

Please use this thread to ask the related questions.

AEM AEMEBlogSeeding Experience Manager