Knowledge Base

Working With Custom Hooks: OnMoveTaxonomy

The taxonomy system in the Ingeniux CMS is a hierarchical structure of categories used for querying, filtering, and sorting content. We look at how the OnMoveTaxonomy custom hook can be used to create parameters around how and when a category is moved in the Taxonomy Tree.


The taxonomy system in the Ingeniux CMS is a hierarchical structure of categories used for querying, filtering, and sorting content.

Categories are stored and managed in the Taxonomy Manager in what is called a Taxonomy Tree. Within the tree, categories are automatically alphabetized for efficiency. There are no folders or other types of content in the Taxonomy Manager – just categories. Because of this, categories are usually organized under other categories (container categories) that are meant to identify their type, such as a Products category that is above all categories used for working with product content.

Figure: Sample Category Structure

The Taxonomy Navigation Element is a field that can be placed on pages or components to query the taxonomy system. When a container category is entered into this field, the navigation element will pull in its descendants (using the Depth field) to build and display a list of relevant categories, often for on-page filtering.

Figure: Sample Taxonomy Navigation Querying a Category and Descendants

Moving a category means changing which container category it appears under in the structure. When a container category is moved all descendants of that category are also moved.

How To Trigger the Hook 

This method is triggered through the following actions:

  • Clicking on a taxonomy category and dragging it to a new location under a different container category.

Note: The above only applies to CMS 10.5 and below.

When to Use This Custom Hook 

CMS Administrators might be interested in setting up dynamic and detailed parameters around how and when a category is moved. For example, they may want to:

  • Control who can move a category (without taking away all taxonomy management privileges – see example directly below).
  • Control parameters around pre-defined possible move destinations, such as only allowing a category to be moved to an archived category area.
  • Trigger other affected content to update.
  • Send notifications to higher level groups to review the change.

For example, in Users/Groups in the Administration Section of the CMS, Administrators can set permissions to limit who can move Categories by navigating to the section titled Permissions on taxonomy system. Here, the permission can be set to allow or disallow a user/group to move categories by checking or unchecking the box for “Allowed to Manage the Taxonomy System.” By unchecking this box, you take away the user’s ability to manage or edit taxonomy categories in any way. For Administrators aiming to limit a user’s ability to move categories while maintaining their ability to work in the taxonomy system in other ways, they’ll need to turn to this custom hook.

Considerations

It’s best to avoid moving categories around once a Taxonomy Tree structure has been established and is in use. However, during the initial building phases, it’s pretty common to move categories around as you work to define a structure. It may be best to wait until a site is established before coding into this hook.

Moving a container category moves all its descendants but those moves don’t individually trigger the hook. Make sure to take this into account with your scripts.

Example 

Prevent category moves by non-administrators

In this example, the script checks to see if the user attempting a move is in a specified group. If they are not, then the action is blocked.

First, get the allowed group. This example uses the Administrators group, but you can specify your own by ID.

Next, get the users from that group in a collection. Then, get the current user from the session.

Finally, if the current user is in the specified group of users, allow the action. Otherwise, throw an error that prevents the operation from completing.

string adminstratorGroup = "UserGroups/1";

IEnumerable<IUser> adminstratorGroupUsers = session.UserManager.UserGroup(adminstratorGroup).Users(out int count);

var currentUser = session.Site.CurrentUser;

 if (!adminstratorGroupUsers.Contains(currentUser))

{

       throw new Exception("Current User does not have Administrator Level Access to Move Taxonomy");

}

Ways to Extend the Functionality Further 

This example allows access to the Administrators user group. This code can be adjusted to allow any user group of choice.

It’s possible that sections of the Taxonomy Tree are owned by different groups. If this is the case, you can set up a permission check for groups such as event editors, news editors, and product managers. You could tie those sections of taxonomy to individual groups to spread out the editing overhead.

If you were truly only concerned with the Administrators group, then there is also an IsAdministrator property on CurrentUser that would facilitate this check.

  • PRODUCT: CMS
  • VERSION: CMS 10
  • RELEASE: 10.x
  • Published: April 10, 2023
  • LAST UPDATED: September 18, 2023
  • Comments: 0

Please login to comment

Comments


There are no comments yet.