AEM 中的 OOTB Granite 渲染条件

OOTB Granite Render Condition in AEM

我创建了一个名为 annotation 的按钮,并添加了 hasannotation OOTB 花岗岩渲染条件。选择带有注释的图像时,按钮不会呈现。
Image Of the custom button with granite:rendercondition

Properties of the button

Properties of granite:rendercondition node

首先您需要将 granite:rel 属性 添加到您的按钮。 正如 documentation 中所说:

This is used to indicate the semantic relationship of the component similar to HTML rel attribute.

您可以在自定义按钮中添加 AEM 现有 granite:rel 作为 "aem-assets-admin-actions-annotate-activator",如图 /libs/dam/gui/content/assets/jcr:content/actions/selection/annotate

或者您也可以添加自定义值,比如 "my-annotation-rel"。在这种情况下,您需要告诉 AEM 考虑您的自定义值。为此,您需要叠加 /libs/dam/gui/coral/components/admin/contentrenderer/base/assetBase.jsp 并添加这一行:

 actionRels.add("my-annotation-rel");

更新: 渲染条件不工作,因为路径没有正确传递给 redercondition 组件。 {requestPathInfo.suffix} 不提供资产的实际路径,而是提供文件夹路径,因此当您处于 card/column/list 视图时无法检查。

为了实现这一点,请按照下列步骤操作:

  1. 覆盖/libs/dam/gui/coral/components/admin/contentrenderer/base/base.jsp
  2. 在 getActionRels(Node node, boolean hasReplicate,boolean hasRemoveNode, boolean hasModifyAccessControl, boolean isExpiredAsset, boolean isExpiredSubAsset, boolean isDAMAdmin, boolean isContentFragment) 方法中添加以下代码

    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");
      }
    
  3. 将 granite:rel(字符串)"my-annotation-rel" 属性 添加到您的自定义按钮

应该可以。

不更改 OOTB jsp 文件行为的另一种方法,如果您正在自定义元数据编辑器,那么花岗岩渲染条件应该可以工作。在这种情况下,您必须首先覆盖此按钮和您的自定义按钮:

 /libs/dam/gui/content/assets/metadataeditor/jcr:content/actions

并在您的自定义按钮下添加 granite:rendercondition 节点并将路径 属性 指定为

 ${empty requestPathInfo.suffix ? param.item : requestPathInfo.suffix}