How to filter the pages visible in an AEM Granite UI Path Browser?

跟風遠走 提交于 2021-02-07 09:32:33

问题


In the AEM Classic UI has a pathfield xtype that allows the programmer to specify a predicate attribute in order to filter the selectable pages.

The value of the predicate attribute determines which pages are shown in the pathfield. There is a number of OOTB predicates such as 'hierarchy', 'folder', 'hierarchyNotFile', etc.

One can provide a custom predicate by writing an OSGi service implementing the org.apache.commons.collections.Predicate class. Specifically, the implementation is selected by the value of the predicate.name property.

For example:

@Service(Predicate.class)
@Component(metatype = false)
@Properties(@Property(name = "predicate.name", value = "productPage"))
public class ProductPagePredicate extends com.day.cq.commons.predicate.AbstractNodePredicate {

    @Override
    public boolean evaluate(Node n) {
       // return true or false depending on the state of the node
    }
}

could be used the following way:

<productPath
    jcr:primaryType="cq:Widget"
    allowBlank="false"
    predicate="[productPage]" <-- refers to the OSGi service
    fieldLabel="Product"
    name="./productPath"
    xtype="pathfield"/>

Is there a way to achieve a similar level of customization in the Touch UI equivalent of the path field?

I can see that the widget granite/ui/components/foundation/form/pathbrowser is used by a number of OOTB components (foundation/components/image among others). It looks like a 1:1 replacement of the path field in the new interface. However, I can't find any references to it in the Granite UI documentation for AEM 6.2

The field looks something like this:

Clicking it brings up a nice interface where one can select a page or asset:

How can I filter the pages available in a Touch UI Path Browser? Is there a way to make it use a Predicate previously defined for use in Classic UI?


回答1:


In AEM 6.2 this works in the same way as before and predicates created in earlier versions can be reused.

You can find example in geometrixx:

/libs/foundation/components/reference/cq:dialog/content/items/column/items/reference

Here's the field definition itself (serialised to XML for the purpose of this post)

<reference
    fieldLabel="Reference"
    jcr:primaryType="nt:unstructured"
    name="./path"
    predicate="nosystem"
    rootPath="/content"
    sling:resourceType="granite/ui/components/foundation/form/pathbrowser" />

You can see how a component using this field looks on this Geometrixx page:

/content/geometrixx/en/company/bod/jcr:content/par/reference_1


来源:https://stackoverflow.com/questions/41677562/how-to-filter-the-pages-visible-in-an-aem-granite-ui-path-browser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!