Sitefinity CMS

Setting up the Project Send comments on this topic.
Modules > Custom Modules > Pluggable Modules > Building the Contacts Pluggable Module > Setting up the Project

Glossary Item Box

The basic concepts of a Sitefinity module are explained in Concepts. This topic goes further into creating the basic code in order to set up the project.

 

Creating the Project

Important Classes

In order to create a module, a new C# project should be created. To start up, there should be just three files inside this project. Regardless of the kind of module to be built these files are required:

  • The Module class
  • Two Web Control classes
    • Command Panel
    • Control Panel

 

 

References

In addition to classes, there needs to be a reference to the following assemblies in the project:

  • System
  • System.Data
  • System.Drawing
  • System.IO
  • System.Web
  • System.Web.UI
  • System.Web.UI.WebControls
  • System.Web.UI.HtmlControls
  • System.Xml
  • Telerik.Cms.Web.UI
  • Telerik.Framework
  • Telerik.Security
  • Telerik.Web
  • Telerik.WebControls

 

The sample module that will be built and used throughout this section "Building a Module" is the “Contacts” module. This is a very simple module which allows users to enter all relevant contacts across the organization (for example : CEO, sales, technical support, and so on) with their names, e-mails, phone numbers, working hours and so on. 

Click here to download the Contacts project

 

The first file in the sample project which will hold the Contacts module is the ContactsModule class. This is our module class and it has to inherit from the Telerik.WebModule class in order to be used as a Sitefinity module. Apart from several properties that describe this module (such as name and description), there are two important methods here. They are:

  • CreateControlPanel
  • CreateToolBoxControls

 

To implement them, there are two necessary files: the ControlPanel class (of type ControlPanelBase) and the CommandPanel class (of type CommandPanelBase). The CreateControlPanel method returns any Control that will be used as a ControlPanel control (the right-sided part; for more information see Concepts). The CreateToolBoxControls returns an IList<IToolboxItem> object, which in turn contains all controls you want to appear in the CommandPanel (the left-sided part).

 

All this is part of the ContactsModule class. Namely, in CreateControlPanel method a new instance of the ControlPanel class is created and returned, while in CreateToolBoxControls a new instance of CommandPanel class is created and added to the IControlPanelCommand array.

 

And this is all that is needed to get the Contacts module working. In ControlPanel and CommandPanel classes you can overwrite the CreateChildControls method and add just some arbitrary controls (for example, add some labels) to see what happens.

 

Since Sitefinity 3.1 we have introduced two new classes and a slight change in logic. The two new classes are:

  • Telerik.Web.ControlPanelBase 
  • Telerik.Web.CommandPanelBase


Take a look at the following diagram to get a general idea of these improvements. Later all is explained in a bit more detail:

 

So instead of implementing the IControlPanel interface on your ControlPanel classes,  make that class inherit the Telerik.Web.ControlPanelBase. In the same way instead of implementing IControlPanelCommand interface on your CommandPanel classes, make that class inherit the Telerik.Web.CommandPanelBase class.

In addition to that, constructors must be added for ControlPanel and CommandPanel classes.
Here is the constructor for CommandPanel:

CommandPanel Copy Code
public CommandPanel(ControlPanel controlPanel)  
           :
base(controlPanel)  
{  
}   

 

And here is the constructor for ControlPanel:

ControlPanel Copy Code
public ControlPanel()  
{  
 
base.commandPnls = new ICommandPanel[] { new CommandPanel(this) };  
}   

Notice how the ControlPanel constructor actually creates a new instance of the CommandPanel class. Here are the reasons why this should be done:

  1. Direct access - from CommandPanel to ControlPanel and vice versa (this.ControlPanel and this.CommandPanel).
  2. No events creation - to refresh the ControlPanel if something is changed in CommandPanel (for example, deleted), there is no need to create events for that anymore. All that must be done is to call this.ControlPanel.Refresh() from CommandPanel instance. CommandPanel also has the Refresh() method.

 

 

Next Topic 

In the topic Registering a Module you can find explanation and code for registering a Module in Sitefinity.