toniedzwiedz
toniedzwiedz

Reputation: 18553

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

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:

Path Browser field in a Touch UI dialog

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

Path selection in the path browser field

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?

Upvotes: 3

Views: 5867

Answers (1)

rzasap
rzasap

Reputation: 346

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

Upvotes: 6

Related Questions