Write and Configure a Category Filter

You can implement a custom category filter to control which categories are visible in the taxonomy picker. For example, you may want to hide certain categories based on the current user or specific properties on the category node. To do this, implement the JcrCategoryFilter interface in your CMS project.

Important:
If you hide categories for some users (such as user group A) but allow other users (user group B) to assign those categories to documents, users in group A may encounter "Invalid category key" errors in the taxonomy picker when editing documents that reference hidden categories. Design your use case to prevent this scenario.

import org.onehippo.taxonomy.plugin.api.JcrCategoryFilter; /** * Category filter that hides categories if they do not have a specific property. */ public class MyCategoryFilter implements JcrCategoryFilter { @Override public boolean apply(final JcrCategory category, final HippoSession session) { // Hide categories for the user with ID "author" if (session.getUser().getId().equals("author")) { return false; } // Hide categories that do not have the "myproject:authorized" property if (!category.getJcrNode().hasProperty("myproject:authorized")) { return false; } // Show the category in all other cases return true; } }

For a reference implementation, see the filter in the Taxonomy Essentials demo feature: HideForAuthorCategoryFilter.java.

Configure the Category Filter

Register your filter implementation by setting the following property on the taxonomy service:

/hippo:configuration/hippo:frontend/cms/cms-services/taxonomyService: taxonomy.category.filters: com.myproject.cms.taxonomy.MyCategoryFilter

To use multiple filter classes, specify them as a comma-separated list.

Share Feedback
Page: /build/plugins/taxonomy/write-and-configure-a-category-filter
Section: Build
Category *