Extend forms connectors definitions

If you have custom connector and you want it to have settings in the forms detail dialogs. You can achieve this using FormsConnectorDefinitionsExtender.

Add custom controls to forms section separated for the connectors, by performing the following:

  1. Create your own class and implement the abstract FormsConnectorDefinitionsExtender.

  2. Use the AddConnectorsSettings method to attach your custom controls to the form dialogs. Use the following sample:

    C#
    using System;
    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Modules.Forms;
    using Telerik.Sitefinity.Services;
    using Telerik.Sitefinity.Web.UI.Fields;
    using Telerik.Sitefinity.Web.UI.Fields.Config;
    using Telerik.Sitefinity.Web.UI.Fields.Enums;
    
    namespace SitefinityWebApp
    {
        public class ExtendFormConnector : FormsConnectorDefinitionsExtender
        {
            public override void AddConnectorSettings(ConfigElementDictionary<string, FieldDefinitionElement> sectionFields)
            {
                var myTextField = new TextFieldDefinitionElement(sectionFields)
                {
                    Title = "myTextField",
                    DataFieldName = string.Format("{0}.{1}", "Attributes", "myFieldName"),
                    DisplayMode = FieldDisplayMode.Write,
                    FieldName = "myFieldName",
                    FieldType = typeof(TextField),
                    ID = "myId",
                    ResourceClassId = "myClass",
                };
    
                sectionFields.Add(myTextField);
            }
    
            public override int Ordinal
            {
                get { return 1; }
            }
    
            public override string ConnectorName => "MyConnectorName";
    
            public override string ConnectorTitle => "MyConnectorTitle";
    
            public override string SectionTitle => "MyConnectorSectionTitle";
        }
    }

    NOTE: Sitefinity CMS supports only the following definition elements as section fields: TextFieldDefinitionElement, ChoiceFieldElement, and TaxonFieldDefinitionElement.

    NOTE: FormsConnectorDefinitionsExtender.ConnectorName and IModuleConnectionStatus.ModuleName must be equal.

  3. Implement the IModuleConnectionStatus interface

    Sitefinity CMS displays the warning Connection to [Connector Title] is not set or lost. Check your connector settings and try again when the following conditions are met:

    • Your connector does not implement the IModuleConnectionStatus interface.
    • The action callback of the IModuleConnectionStatus.ExecuteIfConfigured method was not executed.

    To prevent showing this warning to the Sitefinity CMS user, implement the interface as the following example:

    C#
    using System;
    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Modules.Forms;
    using Telerik.Sitefinity.Services;
    using Telerik.Sitefinity.Web.UI.Fields;
    using Telerik.Sitefinity.Web.UI.Fields.Config;
    using Telerik.Sitefinity.Web.UI.Fields.Enums;
    
    namespace SitefinityWebApp
    {
        public class ExtendFormConnectorConnectionStatus : IModuleConnectionStatus
        {
            public string ModuleName => "MyConnectorName";
    
            public void ExecuteIfConfigured(Action action)
            {
                  // Add code to check that the connector is connected
                  // ex. if (this.connector.IsConnected())
                  if (action != null)
                      action();
            }
    
            // IMPORTANT: This callback is not invoked as part of Forms connectors. You still need to implement it, as it is used elsewhere.
            public void ExecuteIfNotConfigured(Action action)
            {
                  // Add code to check that the connector is not configured
                  // ex. if (!this.connector.IsConnected())
                  if (action != null)
                      action();
            }
        }
    }
  4. Register your classes in the following way:

    C#
    using System;
    using Telerik.Microsoft.Practices.Unity;
    using Telerik.Sitefinity.Abstractions;
    using Telerik.Sitefinity.Services;
    
    namespace SitefinityWebApp
    {
        public class Global : System.Web.HttpApplication
        {
            protected void Application_Start(object sender, EventArgs e)
            {
                Bootstrapper.Bootstrapped += Bootstrapper_Bootstrapped;
            }
    
            private void Bootstrapper_Bootstrapped(object sender, EventArgs e)
            {
                ObjectFactory.Container.RegisterType<Telerik.Sitefinity.Modules.Forms.FormsConnectorDefinitionsExtender, ExtendFormConnector>("ExtendFormConnector");
                ObjectFactory.Container.RegisterType<IModuleConnectionStatus, ExtendFormConnectorConnectionStatus>(typeof(ExtendFormConnectorConnectionStatus).FullName, new ContainerControlledLifetimeManager());
            }
        }
    }

    The Ordinal property is used to sort the connectors settings.

Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
New to Sitefinity?