green field

Module Settings - A Developer Convenience

Often you will need to store configuration properties for your custom feature. For example the Contact Form Feature has a setting for the email address to send the message to when the form is posted. This is an instance level setting because I could have more than one Contact Form with different email addresses, so each instance of the Contact Form needs to store the instance specific setting somewhere.

You could implement your own system for managing settings in your feature and for very elaborate features that may be the best way to go, but for simple scenarios you can save some development effort by using the Module Settings system included in mojoPortal which allows you to store arbitrary properties that can be serialized as strings. You can define your settings as using either TextBox or CheckBox. When you use TextBox, you can also specify a RegularExpression used to validate values entered for the setting.

It is possible to define new module settings using the Site Administrative Features under Admin Menu > Feature Definitions > Feature Definition Settings, but typically its easier to just specify them in the FeatureDefinition file and then visit the Setup/Default.aspx page to run setup. It will add any missing Module Settings to the database based on your configuration file. Typically you put the FeatureDefinition files beneath Setup
 Applcations
   yourapplicationname
     FeatureDefinitions

See the examples for the included features under Setup/applications/mojoportal-core/FeatureDefinitions

You get to the Module Settings page for a feature instance by clicking the gears icon next to the title. There you will see a few core module properties defined in the SiteModuleControl base class and then you will see any custom feature specific module settings.

In the code for your ModuleControl (which inherits from SiteModuleControl) you can access settings from the intrinsic hashtable named Settings like this:

Settings["ContactFormEmailSetting"].ToString()

or

UseSpamBlocking = WebUtils.ParseBoolFromHashtable(
Settings, "ContactFormUseCommentSpamBlocker", false);

If your feature has supporting pages like the Blog and Forums do, you may need to be able to lookup these settings from there to. In that case you can get them like this:

Hashtable moduleSettings = ModuleSettings.GetModuleSettings(ModuleID);
ShowCategories = WebUtils.ParseBoolFromHashtable(
moduleSettings, "BlogShowCategoriesSetting", false);

As I mentioned, for very complex features the Module Settings may prove too limiting. For example in developing the e-commerce feature I found that since the store had quite a few more complex settings it was better to implement a custom feature for managing them so I could have complete control over the presentation of the settings and could make some settings only configurable by certain roles.

Last Updated 2007-09-04

mojoPortal Wins the 2007 Open Source CMS Awards Best Non-PHP Open Source CMS Donate Money to support the mojoPortal Project. Join the mojoPortal Group on Facebook Join the mojoPortal Group on LinkedIn View Joe Audette's profile on LinkedIn View Joe Audette's profile on The Guild of Accessible Web Designers site mojoPortal can run on GNU/Linux using Mono