using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using umbraco.interfaces; using Umbraco.Core.Logging; using Umbraco.Core.ObjectResolution; namespace Umbraco.Core.Macros { /// /// A resolver to return all IMacroGuiRendering objects /// /// /// Much of this classes methods are based on legacy code from umbraco.editorControls.macrocontainer.MacroControlFactory /// this code should probably be reviewed and cleaned up if necessary. /// internal sealed class MacroFieldEditorsResolver : LazyManyObjectsResolverBase { /// /// Constructor /// /// /// /// internal MacroFieldEditorsResolver(IServiceProvider serviceProvider, ILogger logger, Func> macroEditors) : base(serviceProvider, logger, macroEditors, ObjectLifetimeScope.Transient) { } /// /// Gets the implementations. /// public IEnumerable MacroFieldEditors { get { return Values; } } /// /// Gets the value based on the type of control /// /// /// /// /// This is legacy code migrated from umbraco.editorControls.macrocontainer.MacroControlFactory /// internal string GetValueFromMacroControl(Control macroControl) { return HttpUtility.HtmlDecode(((IMacroGuiRendering)macroControl).Value); } /// /// This is legacy code migrated from umbraco.editorControls.macrocontainer.MacroControlFactory /// internal List MacroControlTypes { get { return InstanceTypes.ToList(); } } /// /// Create an instance of a Macro control and return it. /// Because the macro control uses inline client script whichs is not generated after postback /// That's why we use the Page Picker instead of the content picker of the macro. /// /// /// This is legacy code migrated from umbraco.editorControls.macrocontainer.MacroControlFactory /// internal Control GetMacroRenderControlByType(PersistableMacroProperty prop, string uniqueId) { var m = MacroControlTypes.FindLast(macroGuiCcontrol => macroGuiCcontrol.ToString() == string.Format("{0}.{1}", prop.AssemblyName, prop.TypeName)); var instance = ServiceProvider.GetService(m) as IMacroGuiRendering; if (instance != null) { if (string.IsNullOrEmpty(prop.Value) == false) { instance.Value = HttpUtility.HtmlDecode(prop.Value); } var macroControl = instance as Control; if (macroControl != null) { macroControl.ID = uniqueId; return macroControl; } } return null; } } }