More in this section
Blogs RSS feed

Transferring modules built prior to Sitefinity 3.6 to the new backend architecture: Breaking Control Panel modes into Views

by User Not Found
[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]


As we have stated in the Overview of this topic, our first task is to break Control Panel modes into Views. Whereas ControlPanel modes used to be only the enumeration on which we used to create (hide or show) different controls, with Views we are actually going to create a separate control (View) for each of these modes.


Let us examine this task on the Sitefinity built-in Lists module. In the old implementation we used to have following enumeration representing various modes of the Lists module ControlPanel:
        /// <summary>Represents the display mode of the <see cref="ControlPanel"/>. </summary> 
        public enum DisplayMode 
            /// <summary>Displays all lists.</summary> 
            /// <summary>Displays a single list and all of its items.</summary> 
            /// <summary>Adds a new list.</summary> 
            /// <summary>Edits an existing list.</summary> 
            /// <summary>Adds a new item.</summary> 
            /// <summary>Edits an existing item.</summary> 
            /// <summary>Manages permissions of the lists module</summary> 
Then, depending on the currently selected mode we would create the user interface in the CreateChildControls method, which used to look like this:
            switch (this.mode) 
                case DisplayMode.AllLists: 
                case DisplayMode.NewList: 
                case DisplayMode.EditList: 
                case DisplayMode.ViewList: 
                case DisplayMode.NewItem: 
                case DisplayMode.EditItem: 
                case DisplayMode.Permissions: 
With further conditioning implemented in the CreateAllLists, CreateListView and CreatePermissionsView methods.


So, the first order of business is to create Views for each of the modes ControlPanel had. By doing that, we’ve ended up with following Views in the new implementation of the Lists module:

  • AllListsView
  • ListEdit
  • ListInsert
  • ListItemEdit
  • ListItemInsert
  • ListItemsAll
  • ListsAll
  • PermissionsView

You can see that the Views are following the modes very closely in their functionality and intention.


Now, that the Views have been created, new Sitefinity backend architecture will take care of all these conditions that we used to have to implement in order to always display correct UI. Once the Views are defined, we need to separate the ControlPanel template into a separate template for each View and finally move the event handlers and methods of ControlPanel to their respective Views.


With the Views separated, we can follow the instructions described in articles “What are Views?” and “Adding Views to ControlPanel” to wire up all the Views together into a module hierarchy.

Leave a comment