Override Data Actions

Attach conditional, or override default, actions on the tree elements in the CMS Console.

You can override a default action or attach an action, a workflow, a message box, or any other custom actions to a data element by registering it with one of the following methods on the application startup:

  • RegisterConditional
  • RegisterDefault

For this, create a new class and decorate it with [ApplicationStartup] with two public static methods: OnBeforeInitialize() (not used here) and OnInitialized().

(Read more on using [ApplicationStartup].)

You can build a DLL with this class and copy it to /Bin, or place the class in /App_Code.

Attaching conditional actions

To attach a conditional action, call the RegisterConditional method of DataActionTokenResolverFacade and define your condition, your action and when this action should be called. Place the call to this method in OnInitialized():

namespace Composite
{
    [ApplicationStartup]
    public static class OverrideDataActions
    {
        /// <exclude />
        public static void OnBeforeInitialize()
        {
            
        }

        /// <exclude />
        public static void OnInitialized()
        {
            Guid blogDataTypeGUID = new Guid("bea4f923-4b10-44e7-b290-c2c0ca671ea7");
            Guid pageDataTypeGUID = new Guid("f7869eb2-7369-4eb2-af47-e3be261e92c7");

            //Registering Conditional Actions
            DataActionTokenResolverFacade.RegisterConditional<IPage>(
				ActionIdentifier.Add, 
				f1 => f1.PageTypeId == blogDataTypeGUID, 
				f2 => new MessageBoxActionToken(
					"Sample Add Action", 
					"Some Information on Adding Blog", 
					DialogType.Message));
			
            DataActionTokenResolverFacade.RegisterConditional<IPage>(
				ActionIdentifier.Publish, 
				f1 => f1.PageTypeId == blogDataTypeGUID && DateTime.Now.Day % 2 == 0, 
				f2 => new MessageBoxActionToken(
					"Sample publish Action", 
					"You can publish blog on odd days", 
					DialogType.Message));
			
            DataActionTokenResolverFacade.RegisterConditional<IPage>(
				ActionIdentifier.Edit, 
				f1 => f1.PageTypeId == pageDataTypeGUID, 
				f2 => new MessageBoxActionToken(
					"Sample Edit Action", 
					"Some Information on Edit Page", 
					DialogType.Message));
        }
    }
} 

Download the code

This replaces:

  • the default adding action for a page with a message box if the page’s type is "Blog"
  • the publishing action for a page with a message box if the page's type is "Blog" and the day is even
  • the default editing action for a page of the specified type with a message box

Overriding default actions

You can also override default actions for data elements by calling the RegisterDefault method. Place the call to this method in OnInitialized():

namespace Composite
{
    [ApplicationStartup]
    public static class OverrideDataActions
    {
        /// <exclude />
        public static void OnBeforeInitialize()
        {
            
        }

        /// <exclude />
        public static void OnInitialized()
        {
            //Overriding Default Actions
            DataActionTokenResolverFacade.RegisterDefault<IPage>(
				ActionIdentifier.Unpublish, 
				f => new MessageBoxActionToken(
					"New Unpublishing Routine", 
					"This messagebox has overrided your default unpublishing action", 
					DialogType.Message));
        }
    }
}

Download the code

This would replace the unpublishing action on all pages with a message box.

Requirements

  • C1 CMS version 5.1 or later