Modifying the list of associations shown in the classification editor

Top  Previous  Next

The TMCore EPiServer Module creates as list of association types that will be rendered as slots in the classification editor:

Association slots derived from the topic map schema shown in the classification editor

Association slots derived from the topic map schema shown in the classification editor

This list is created in code as a list of instances of NetworkedPlanet.EPiServerModule.Schema.AssociationField objects, and then converted to a serialized JSON object.

It is possible for administrators to deploy a plug-in that edits the list of associations slots shown in the classification editor by registering an event handler with the TopicTypeSchemaInitialized event on the NetworkedPlanet.EPiServerModule.Schema.SchemaJSON class. This event is then invoked when the JSON schema for the topic type is calculated, but before final serialization.

This is useful, as an example, for reordering the slots before they are rendered. The following class listing shows how ordering the slots by arc label may be achieved:

using System.Collections.Generic;

using System.Reflection;

using EPiServer.PlugIn;

using log4net;

using NetworkedPlanet.EPiServerModule.Schema;

namespace EPiServerModuleDemo

{

    /// <summary>

    /// Demonstration of using the TopicTypeSchemaInitialized event on <see cref="SchemaJSON"/> to order association fields in the

    /// classification editor

    /// </summary>

    public class AssociationFieldOrdererPlugin : PlugInAttribute

    {

        #region Log Configuration

        /// <summary>

        /// The log4net logger for this class

        /// </summary>

        private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        #endregion

        /// <summary>

        /// Automatically invoked at system start-up by EPiServer

        /// </summary>

        public static void Start()

        {

            SchemaJSON.Instance.TopicTypeSchemaInitialized += Instance_TopicTypeSchemaInitialized;

            SchemaJSON.Instance.FlushSchema();

        }

        /// <summary>

        /// Sort the set of <see cref="AssociationField"/> instance by the arc label

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="args"></param>

        static void Instance_TopicTypeSchemaInitialized(object sender, TopicTypeSchemaDelegateArgs args)

        {

            log.DebugFormat("Sorting list of association fields for {0}({1})", args.TopicTypeSI, args.TopicTypeId);

            List<AssociationField> fields = args.AssociationFields;

            fields.Sort((first, second) => (!string.IsNullOrEmpty(first.ArcLabel) ? first.ArcLabel.CompareTo(

                                               second.ArcLabel) : 0));

        }

    }

}