Knowledge Base

Working With Custom Hooks: OnAssign_Page

Assigning a page or component in the CMS changes the user or group that is allowed to access the content item. Learn how to customize and extend this functionality in the custom hook.


Assigning a page or component in the CMS changes the user or group that is allowed to access the content item. This occurs when a user manually uses the Assign To button in the toolbar or in the right-click context menu when checking out a site tree content item that was previously unassigned, and when advancing a site tree content item through workflow. Users in the CMS can extend this hook to include functionality that will make their work in the CMS easier.

Considerations

This hook is triggered when a page or component is assigned in the CMS. This action can be done in a number of ways, including API calls. Avoid writing code within the hook that would assign the same page that triggered the hook in order to prevent infinite loops.

Additionally, be careful when putting large processes into these hooks, as they are callable through multi-select right-click context and through Page and Children.

Finally, with the potential for the entire site to be assigned all at once, it’s important to remember that your code could be processing on a large amount of content items with a single action.

Example

Assign Associated Components

In the following example, we are aiming to assign a page to a new user or group. In this instance, we want to also assign all of the components on the page to that same user or group, saving them the trouble of finding and taking possession of all of the components manually. We only want to assign the checked-out components since components that are checked-in are not being worked on.

int outVar;

IEnumerable<IElement> pageComponents = page.AllElements().Where(e => e.Type == EnumElementType.IGX_COMPONENT);

var pubTargets = session.PublishingManager.Targets(out outVar);

if (pubTargets.Any() && pageComponents.Any())

{

   foreach (var comp in pageComponents)

   {

     var componentItem = (comp.Value != "") ? session.Site.Page(comp.Value) : null;

 

     if (componentItem != null && componentItem.CheckedOut)

                    {

                        componentItem.AssignUser(session.OperatingUser, "Automated assignment through page assignment hook.");

                    }

    }

}

Assigning a content item does not check to see if anyone else is working on that content item or that the assigned user isn’t already working on that content item currently. It just checks to ensure that the assigned user has the permission to take control of the content item. You could enhance this hook by not allowing content items to be taken away from other users who have logged in recently.

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

Please login to comment

Comments


There are no comments yet.