AEM 6550 - AEM Assets show Tags in List View


Show Tags in List View of Assets and Omni Search Consoles



Assets Console - List View

Omni Search - List View



Solution


1) Add the custom tag column configuration in /apps/dam/gui/content/commons/availablecolumns (Sling Resource Merger combines the otb columns in /libs/dam/gui/content/commons/availablecolumns with ones configured in /apps)

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:primaryType="nt:unstructured">
    <tags
        jcr:primaryType="nt:unstructured"
        jcr:title="EAEM Tags"
        columnGroup="Experience AEM"
        configurable="{Boolean}true"
        default="{Boolean}true"/>
</jcr:root>


2) Add the following code for rendering tag titles in /apps/dam/gui/coral/components/admin/contentrenderer/row/common/reorder.jsp; include the otb reorder.jsp using cq:include

<%@include file="/libs/granite/ui/global.jsp"%>
<%@ page import="org.apache.sling.api.resource.ValueMap" %>
<%@ page import="org.apache.sling.api.resource.Resource" %>
<%@ page import="com.day.cq.tagging.TagManager" %>
<%@ page import="com.day.cq.tagging.Tag" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="com.day.cq.dam.api.Asset" %>
<%@ page import="org.apache.commons.collections.CollectionUtils" %>
<%@ page import="org.apache.commons.lang3.ArrayUtils" %>
<%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0"%>

<%
    final String ASSET_RES_TYPE = "dam/gui/coral/components/admin/contentrenderer/row/asset";

    Resource assetResource = resource;
    TagManager tagManager = assetResource.getResourceResolver().adaptTo(TagManager.class);
    String eaemTags = "";

    if(assetResource.getResourceType().equals(ASSET_RES_TYPE)){
        Object[] tags = (Object[])assetResource.adaptTo(Asset.class).getMetadata("cq:tags");

        if(!ArrayUtils.isEmpty(tags)){
            List<String> tagWords = new ArrayList<String>(tags.length);

            Arrays.stream(tags).forEach(tag -> tagWords.add(tagManager.resolve(tag.toString()).getTitle()));

            eaemTags = String.join(", ", tagWords);;
        }
    }
%>

<td is="coral-table-cell" value="<%= eaemTags %>">
    <%= eaemTags %>
</td>

<cq:include script = "/libs/dam/gui/coral/components/admin/contentrenderer/row/common/reorder.jsp"/>


No comments:

Post a Comment