擴充Asset Editor extending-asset-editor

Asset Editor是點按透過Asset Share找到的資產時開啟的頁面,可讓使用者編輯資產的方面,如中繼資料、縮圖、標題和標籤。

有關使用預先定義的編輯元件來設定編輯器的資訊,請參見 建立和設定Asset Editor頁面.

除了使用現有的編輯器元件之外, Adobe Experience Manager 開發人員也可以建立自己的元件。

建立資產編輯器範本 creating-an-asset-editor-template

Geometrixx中包含下列範例頁面:

  • Geometrixx範例頁面: /content/geometrixx/en/press/asseteditor.html
  • 範例範本: /apps/geometrixx/templates/asseteditor
  • 範例頁面元件: /apps/geometrixx/components/asseteditor

設定Clientlib configuring-clientlib

Assets 元件使用WCM edit clientlib的擴充功能。 clientlibs通常載入到 init.jsp.

與預設clientlib載入(在核心的 init.jsp),和 Assets 範本必須具備下列條件:

  • 範本必須包含 cq.dam.edit clientlib (而非 cq.wcm.edit)。

  • clientlib也必須包含在停用的WCM模式中(例如,載入 publish),才能轉換謂語、動作和鏡頭。

在大多數情況下,複製現有的範例 init.jsp (/apps/geometrixx/components/asseteditor/init.jsp)應該能滿足這些需求。

設定JS動作 configuring-js-actions

部分 Assets 元件需使用JS函式,定義於 component.js. 將此檔案複製到您的元件目錄並加以連結。

<script type="text/javascript" src="<%= component.getPath() %>/component.js"></script>

此範例將此JavaScript來源載入到 head.jsp(/apps/geometrixx/components/asseteditor/head.jsp)。

其他樣式表 additional-style-sheets

部分 Assets 元件使用widget資料庫。 若要在內容內容內容中正確呈現,必須載入其他樣式表。 標籤動作元件需要另一個專案。

<link href="/etc/designs/geometrixx/ui.widgets.css" rel="stylesheet" type="text/css">

Geometrixx樣式表 geometrixx-style-sheet

範例頁面元件要求所有選取器開頭為 .asseteditorstatic.css (/etc/designs/geometrixx/static.css)。 最佳實務:全部複製 .asseteditor 選取器至您的樣式表,並視需要調整規則。

FormChooser:最終載入資源的調整 formchooser-adjustments-for-eventually-loaded-resources

Asset Editor會使用「表單選擇器」,只要將表單選擇器和表單路徑新增至資產的URL,即可讓您編輯相同表單頁面上的資源(此案例中為資產)。

例如:

中的範例控制代碼 head.jsp (/apps/geometrixx/components/asseteditor/head.jsp),請執行下列動作:

  • 他們可偵測是否已載入資產或是否必須顯示純格式。
  • 如果載入資產,則會停用WCM模式,因為parsys只能在純表單頁面上編輯。
  • 如果資產已載入,他們會使用其標題,而非表單頁面上的標題。
 List<Resource> resources = FormsHelper.getFormEditResources(slingRequest);
    if (resources != null) {
        if (resources.size() == 1) {
            // single resource
            FormsHelper.setFormLoadResource(slingRequest, resources.get(0));
        } else if (resources.size() > 1) {
            // multiple resources
            // not supported by CQ 5.3
        }
    }
    Resource loadResource = (Resource) request.getAttribute("cq.form.loadresource");
    String title;
    if (loadResource != null) {
        // an asset is loaded: disable WCM
        WCMMode.DISABLED.toRequest(request);

        String path = loadResource.getPath();
        Asset asset = loadResource.adaptTo(Asset.class);
        try {
            // it might happen that the adobe xmp lib creates an array
            Object titleObj = asset.getMetadata("dc:title");
            if (titleObj instanceof Object[]) {
                Object[] titleArray = (Object[]) titleObj;
                title = (titleArray.length > 0) ? titleArray[0].toString() : "";
            } else {
                title = titleObj.toString();
            }
        }
        catch (NullPointerException e) {
            title = path.substring(path.lastIndexOf("/") + 1);
        }
    }
    else {
        title = currentPage.getTitle() == null ? currentPage.getName() : currentPage.getTitle();
    }

在HTML部分中,使用先前的標題集(資產或頁面標題):

<title><%= title %></title>

建立簡單的表單欄位元件 creating-a-simple-form-field-component

此範例說明如何建立可顯示並顯示已載入資產中繼資料的元件。

  1. 在專案目錄中建立元件資料夾,例如 /apps/geometrixx/components/samplemeta.

  2. 新增 content.xml 以及下列程式碼片段:

    code language-xml
    <?xml version="1.0" encoding="UTF-8"?>
    <jcr:root xmlns:sling="https://sling.apache.org/jcr/sling/1.0" xmlns:cq="https://www.day.com/jcr/cq/1.0" xmlns:jcr="https://www.jcp.org/jcr/1.0"
        jcr:primaryType="cq:Component"
        jcr:title="Image Dimension"
        sling:resourceSuperType="foundation/components/parbase"
        allowedParents="[*/parsys]"
        componentGroup="Asset Editor"/>
    
  3. 新增 samplemeta.jsp 以及下列程式碼片段:

    code language-javascript
    <%--
    
      Sample metadata field component
    
    --%><%@ page import="com.day.cq.dam.api.Asset,
                     java.security.AccessControlException" %><%
    %><%@include file="/libs/foundation/global.jsp"%><%
    
        String value = "";
        String name = "dam:sampleMetadata";
        boolean readOnly = false;
    
        // If the form page is requested for an asset loadResource is the asset.
        Resource loadResource = (Resource) request.getAttribute("cq.form.loadresource");
    
        if (loadResource != null) {
    
            // Determine if the loaded asset is read only.
            Session session = slingRequest.getResourceResolver().adaptTo(Session.class);
            try {
                session.checkPermission(loadResource.getPath(), "set_property");
                readOnly = false;
            }
            catch (AccessControlException ace) {
                // checkPermission throws exception if asset is read only
                readOnly = true;
            }
            catch (RepositoryException re) {}
    
            // Get the value of the metadata.
            Asset asset = loadResource.adaptTo(Asset.class);
            try {
                value = asset.getMetadata(name).toString();
            }
            catch (NullPointerException npe) {
                // no metadata dc:description available
            }
        }
    %>
    <div class="form_row">
        <div class="form_leftcol">
            <div class="form_leftcollabel">Sample Metadata</div>
        </div>
        <div class="form_rightcol">
            <%
            if (readOnly) {
                %><c:out value="<%= value %>"/><%
            }
            else {
                %><input class="text" type="text" name="./jcr:content/metadata/<%= name %>" value="<c:out value="<%= value %>" />"><%
            }%>
        </div>
    </div>
    
  4. 若要讓元件可用,您必須能夠加以編輯。若要讓元件可編輯,請在CRXDE Lite中新增節點 cq:editConfig 主要型別的 cq:EditConfig. 為了能夠移除段落,請新增多值屬性 cq:actions 單一值為 DELETE.

  5. 導覽至您的瀏覽器,並在範例頁面上(例如, asseteditor.html)切換至設計模式,並為段落系統啟用新元件。

  6. 在「 編輯 」模式中,新元件(例如,「範例中繼資料 」)現在可在sidekick中使用(可在「資產編輯器」 ​群組中找到 ​)。插入元件。若要儲存中繼資料,必須將其新增至中繼資料表格。

修改中繼資料選項 modifying-metadata-options

您可以修改中的可用名稱空間 中繼資料表單.

目前可用的中繼資料定義於 /libs/dam/options/metadata

  • 此目錄中的第一個層級包含名稱空間。
  • 每個名稱空間內的專案代表中繼資料,例如本機零件專案中的結果。
  • 中繼資料內容包含型別和多值選項的資訊。

這些選項可以在下列位置覆寫: /apps/dam/options/metadata

  1. 複製目錄來源 /libs/apps.

  2. 移除、修改或新增專案。

NOTE
如果您新增名稱空間,則必須在您的存放庫/CRX中註冊它們。 否則,提交中繼資料表單將會導致錯誤。
recommendation-more-help
19ffd973-7af2-44d0-84b5-d547b0dffee2