Write and Configure a Category Filter
If you have a use case where you want to hide categories in certain circumstances, e.g. based on the current user or some data on the category node, you can create an implementation of the JcrCategoryFilter in your CMS.
Please note that hiding categories for users A while showing them for users B may result in documents with category values on them that are unknown to the users A, resulting in "Invalid category key" in the taxonomy picker. The use case design has to solve that.
import org.onehippo.taxonomy.plugin.api.JcrCategoryFilter; /** * Category filter that hides categories if it doesn't have a certain property. */ public class MyCategoryFilter implements JcrCategoryFilter { @Override public boolean apply(final JcrCategory category, final HippoSession session) { // hide for author if (session.getUser().getId().equals("author")) { return false; } // hide based on absent property if (!category.getJcrNode().hasProperty("myproject:authorized")) { return false; } // OK return true; } }
There is also a filter present in the Taxonomy Essentials demo feature: HideForAuthorCategoryFilter.java
Such a filter can be configured by means of the following taxonomy service property:
/hippo:configuration/hippo:frontend/cms/cms-services/taxonomyService: taxonomy.category.filters: com.myproject.cms.taxonomy.MyCategoryFilter
Multiple filter classes can be specificied as a comma-separated string.