I have created a button called annotation
and I have added hasannotation
OOTB granite render condition. On selection of an image having annotation, the button doesn't get rendered.
Image Of the custom button with granite:rendercondition
First you need to add granite:rel property to your button. As said in the documentation:
This is used to indicate the semantic relationship of the component similar to HTML rel attribute.
You can add the AEM existing granite:rel in your custom button as "aem-assets-admin-actions-annotate-activator" as shown /libs/dam/gui/content/assets/jcr:content/actions/selection/annotate
Or you can also add your custom value lets say "my-annotation-rel". In this case you need to tell AEM to consider your custom value. In order to do this, you need to overlay /libs/dam/gui/coral/components/admin/contentrenderer/base/assetBase.jsp and add this line :
actionRels.add("my-annotation-rel");
Update: render condition is not working because the path is not correctly passed to redercondition component. {requestPathInfo.suffix} does not give the actual path of the asset rather it gives the folder path and hence it fails to check when you are in card/column/list view.
In order to implement this, follow these steps:
Add this below code inside getActionRels(Node node, boolean hasReplicate,boolean hasRemoveNode, boolean hasModifyAccessControl, boolean isExpiredAsset, boolean isExpiredSubAsset, boolean isDAMAdmin, boolean isContentFragment) method
boolean hasAnnotation = false;
NodeIterator nodeItr= node.getNodes();
Node commentsNode;
while(nodeItr.hasNext()) {
Node childNode = nodeItr.nextNode();
NodeIterator childItr = childNode.getNodes();
while(childItr.hasNext()) {
Node secondLevelChild = childItr.nextNode();
if(secondLevelChild.getName().equals("comments")) {
NodeIterator thirdLevelNode = secondLevelChild.getNodes();
while(thirdLevelNode.hasNext()){
if(thirdLevelNode.nextNode().hasProperty("annotationData")){
hasAnnotation = true;
}
}
}
}
}
if(hasAnnotation){
actionRels.add("my-annotation-rel");
}
Add granite:rel (String) "my-annotation-rel" property to your custom button
It should work.
Another way without changing the OOTB jsp file behaviour, if you are customising metadataeditor then granite render condition should work . In this case you have to first overlay this and your custom button:
/libs/dam/gui/content/assets/metadataeditor/jcr:content/actions
and add granite:rendercondition node under your custom button and give path property as
${empty requestPathInfo.suffix ? param.item : requestPathInfo.suffix}