Alfresco Share: how to use evaluator="aspect" to check for (parent) aspect

1.4k views Asked by At

I have one aspect which is the parent aspect of two other aspects.

<aspect name="my:parentAspect">
</aspect> 

<aspect name="my:subAspect1">
    <parent>my:parentAspect</parent>
</aspect>

<aspect name="my:subAspect2">
    <parent>my:parentAspect</parent>
</aspect>

Now I want to use the "aspect"-evaluator in my share-config-custom to apply some customization if a node directly has the aspect "my:parentAspect" or if the node has an aspect that has inherited from "my:parentAspect" by having it as a parent.

<config evaluator="aspect" condition="my:subAspect1">...</config>
<config evaluator="aspect" condition="my:subAspect2">...</config>

works, but I would prefer to use

<config evaluator="aspect" condition="my:parentAspect">...</config>

because the configs for each subAspect are actually all the same.
However, this does not work for nodes that don't have the my:parentAspect directly attached bu only inheriting the aspect.

What's the best practice to check for an aspect regardless whether it's directly applied or inherited somewhere down the hierarchy?

1

There are 1 answers

0
alfrescian On BEST ANSWER

regarding your own comments: don't mix form configs & doclib configs!

org.alfresco.web.config.forms.AspectEvaluator is the Evaluator for form configs like

<config evaluator="aspect" condition="my:parentAspect">...</config>

org.alfresco.web.evaluator.HasAspectEvaluator.java is used for aspect-related evaluator within

<config evaluator="string-compare" condition="DocumentLibrary">

e.g. for indicators, metadata-templates etc. So, org.alfresco.web.config.forms.AspectEvaluator is the one here. It's a subclass of org.alfresco.web.config.forms.NodeMetadataBasedEvaluator that uses the api/metadata Webscript to get the Metadata of the given node:

/api/metadata?nodeRef=" + nodeString + "&shortQNames=true"

This webscript uses org.alfresco.repo.jscript.ScriptNode.toJson() which only includes directly attached aspects.That could be your starting point for a custom Evalutor.