Make custom settings editable by the editor in an module

Maarten van den Hooven asked on October 16, 2015 10:33

I created an custom module with custom settings, where I want to allow the editor to edit the settings themselves?

Does anybody knows if this is possible and how to do this?

Correct Answer

Maarten van den Hooven answered on October 16, 2015 15:23

I succeeded to create an custom module with a page where the editor can change settings. What did I exactly do:

  1. Created a custom module (docs.kentico.com/display/K82/Creating+custom+modules)
  2. Created some custom settings (docs.kentico.com/display/K82/Adding+custom+website+settings)
  3. Created a interface (docs.kentico.com/display/K82/Manually+creating+the+interface+for+custom+modules)
  4. The code of the webform is:

ASPX:

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/CMSMasterPages/UI/SimplePage.master" 
    CodeBehind="SiteSettings.aspx.cs" Theme="Default" Inherits="SiteSettings" %>
<%@ Register TagPrefix="cms" TagName="SettingsGroupViewer" Src="~/CMSModules/Settings/Controls/SettingsGroupViewer.ascx" %>
<asp:content contentplaceholderid="plcContent" id="content" runat="server">
    <cms:SettingsGroupViewer ID="SettingsGroupViewer" runat="server" AllowGlobalInfoMessage="false" />
</asp:content>

ASPX.cs

using CMS.Base;
using CMS.ExtendedControls.ActionsConfig;
using CMS.SiteProvider;
using CMS.UIControls;
using System;
using System.Web.UI.WebControls;

public partial class SiteSettings : CMSModalPage
{
    #region "Page events"

    protected void Page_Load(object sender, EventArgs e)
    {
        // Set up header
        CurrentMaster.HeaderActions.AddAction(new SaveAction(this));
        CurrentMaster.HeaderActions.ActionPerformed += HeaderActions_ActionPerformed;

        // Assign category, group and site ID
        SettingsGroupViewer.CategoryName = "BDO.CustomSettings";
        SettingsGroupViewer.SiteID = SiteContext.CurrentSiteID;
    }

    #endregion

    #region "Event Handlers"

    /// <summary>
    /// Handles actions performed on the master header.
    /// </summary>
    /// <param name="sender">Sender object.</param>
    /// <param name="e">Event argument</param>
    protected void HeaderActions_ActionPerformed(object sender, CommandEventArgs e)
    {
        switch (e.CommandName.ToLowerCSafe())
        {
            case "save":
                SettingsGroupViewer.SaveChanges();
                break;
        }
    }
    #endregion
}
2 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on October 16, 2015 14:02

I'd create a simple webpart as there isn't a way I'm aware of for someone to do this.

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on October 16, 2015 14:26

Hi Brenden,

Thanks for you answer, but maybe I need to clarify my question. I have an custom module where I want the editor to change custom site settings. For example an your Facebook page, this setting is then used in several places of the website. So I added some custom site setting and now I want to add this to the module to allow the editors to change them. It is bit the same as in the eCommerce module where you can also change site settings through the module.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 16, 2015 16:58

Makes more sense now Maarten. Your solution looks awesome, thanks for posting it!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.