This project is read-only.

Creating Import/Export methods for modules under "Settings" in recipe file?

Topics: Customizing Orchard, Writing modules
Apr 15, 2012 at 9:36 PM
Edited Apr 15, 2012 at 9:39 PM

I'm very familiar with import and exporting content types and parts and how to extend modules to leverage the import/export capability of the Import/Export module.  I am however baffled by the <Settings> area of the recipe files.


    <SiteSettingsPart PageTitleSeparator=" - " SiteName="My Site" SuperUser="admin" SiteCulture="en-US" PageSize="6" BaseUrl="" />
    <CommentSettingsPart ModerateComments="true" EnableSpamProtection="false" />
    <SmtpSettingsPart Address="" Host="" Port="587" EnableSsl="true" RequireCredentials="true" UserName="" Password="gsdrye5ye5ye5" />
    <WarmupSettingsPart Urls="/&#xD;&#xA;/passion" Scheduled="true" Delay="90" OnPublish="true" />

I tried to take one example from what exports today when I click "Site Settings"...specially the WarmupSettingsPart and try to figure out what makes it generate in the Export and I'm sorry to say that I came up empty handed.This is the closest I came... finding the method that generates the XML:
        private XElement ExportSiteSettings() {
            var settings = new XElement("Settings");
            var hasSetting = false;

            foreach (var sitePart in _orchardServices.WorkContext.CurrentSite.ContentItem.Parts) {
                var setting = new XElement(sitePart.PartDefinition.Name);

                foreach (var property in sitePart.GetType().GetProperties()) {
                    var propertyType = property.PropertyType;
                    // Supported types (we also know they are not indexed properties).
                    if (propertyType == typeof(string) || propertyType == typeof(bool) || propertyType == typeof(int)) {
                        // Exclude read-only properties.
                        if (property.GetSetMethod() != null) {
                            setting.SetAttributeValue(property.Name, property.GetValue(sitePart, null));
                            hasSetting = true;

                if (hasSetting) {
                    hasSetting = false;

            return settings;

The key appears to be all items that are in the "_orchardServices.WorkContext.CurrentSite.ContentItem.Parts".
1. What Identifies when an item finds it way into "CurrentSite"? The only thing I can find is this: Filters.Add(new ActivatingFilter("Site")); -> WarmupSettingsPartHandler.cs. Can this be done for anything (like UserRoles?)
2. Once exported, how does it import?
Again, the import/export for normal types is easy for me to understand but for these global types, it appears to be a more advanced feature.
Thanks for your assistance!
Apr 16, 2012 at 12:30 AM

Site settings are just a content item. The only thing global about it is that there is only one. As such, it has parts, that import and export like regular parts. That is all.