AEM pathfield to allow selection of only child pages

1.1k views Asked by At

I have a requirement where the AEM pathfield component will show only the child(cq:Page ) resources/nodes of the current node(cq:Page) in the options picker. I went through the documentation https://helpx.adobe.com/experience-manager/6-5/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/form/pathfield/index.html , not sure the filter option can be of use.

@Component(
        service = Predicate.class,
        property = {
                "predicate.name= myPredicateName"
        }
    )
public class MyPredicate extends AbstractNodePredicate {
    private static final LocalisedLogger LOG = LocalisedLoggerFactory.getLogger(MyPredicate.class);

    @Override
    public boolean evaluate(final Node node) {
        LOG.log(Messages.DEBUG, "testing" + node.toString());
        try {
            return isInPredicate(node);
        } catch (RepositoryException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }

    private boolean isInPredicate(final Node node) throws RepositoryException {
        if (node.hasProperty("jcr:content/dog")) {
            return true;
        }
        return false;
    }
}

content.xml

<path
                                                        jcr:primaryType="nt:unstructured"
                                                        sling:resourceType="granite/ui/components/coral/foundation/form/pathfield"
                                                        fieldLabel="Page Path"
                                                        predicate="[myPredicateName]"
                                                        emptyText="Select the carousels page"
                                                        name="./carouselsPagePath"
                                                        forceSelection="{Boolean}true"
                                                        required="{Boolean}true"/>
0

There are 0 answers