Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Robert Dougan 48 posts 154 karma points
    May 20, 2013 @ 12:36
    Robert Dougan
    0

    Creating a Custom Macro Property

    Hi,

    I've been trying to create a new custom macro property (a checkbox list) in 4.11.8 following the instructions in Richard's blog (http://www.richardsoeteman.net/2010/01/04/CreateACustomMacroParameterType.aspx).

    I have created a new class which implements the IMacroGuiRendering interface, inherits from CheckboxList and exists in a separate assembly sitting in the website's bin.

    I have added an entry in the cmsMacroPropertyType table with my assembly name in the macroPropertyTypeRenderAssembly column and my type (minus the assembly name) in the macroPropertyTypeRenderType column.

    I can add the property to a macro, but when I try and use it in either the editor or a Macro Picker data type, I'm unable to specify a value for my custom property.

    Does anyone know what might be going wrong?

    Thanks,

    Robert

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 20, 2013 @ 13:29
    Jan Skovgaard
    0

    Hi Robert

    Could you please post the code your'e currently working on? That way it will be easier to see if there is a typo or something else that could be the cause of the issue or make suggestions.

    /Jan

  • Robert Dougan 48 posts 154 karma points
    May 20, 2013 @ 13:38
    Robert Dougan
    0

    Hi Jan,

    Code is as follows:

    using System;
    using System.Configuration;
    using System.Web.UI.WebControls;
    using umbraco.interfaces;
    using umbraco.NodeFactory;

    namespace MacroProperties
    {
        public class TestimonialPicker : CheckBoxList, IMacroGuiRendering
        {
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
                Node testimonialHome = new Node(Convert.ToInt32(ConfigurationManager.AppSettings["TestimonialsHome"]));
                if (testimonialHome != null)
                {
                    foreach (Node testimonial in testimonialHome.Children)
                    {
                        this.Items.Add(new ListItem(testimonial.Name, testimonial.Id.ToString()));
                    }
                }
            }

            public bool ShowCaption
            {
                get { return true; }
            }

            public string Value
            {
                get
                {
                    return this.SelectedValue;
                }
                set
                {
                    this.SelectedValue = value;
                }
            }
        }
    }

  • Robert Dougan 48 posts 154 karma points
    May 23, 2013 @ 13:47
    Robert Dougan
    0

    As an update, this error is being thrown when I try and add the macro:

    System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object.
       at Umbraco.Core.PluginManager.CreateInstances[T](IEnumerable`1 types, Boolean throwException)
       at Umbraco.Core.ObjectResolution.MacroFieldEditorsResolver.GetMacroRenderControlByType(PersistableMacroProperty prop, String uniqueId)
       at umbraco.editorControls.macrocontainer.MacroEditor.RendeFormControls()
       at System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)
       at System.Web.UI.Page.RaiseChangedEvents()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.HandleError(Exception e)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest()
       at System.Web.UI.Page.ProcessRequest(HttpContext context)
       at ASP.umbraco_editcontent_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\27510986\847481dd\App_Web_editcontent.aspx.5f2dec3.vnl3b665.0.cs:line 0
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
  • Robert Dougan 48 posts 154 karma points
    May 28, 2013 @ 13:53
    Robert Dougan
    100

    I finally solved this.

    The issue was how I had set up the row in the cmsMacroPropertyType table.

    Basically, if your assembly is called MyAssembly, and your type exists in the namespace MyAssembly.Namespace.Type then you need to put "Namespace" into the column macroPropertyTypeRenderAssembly and "Type" into the column macroPropertyTypeRenderType.

Please Sign in or register to post replies

Write your reply to:

Draft