/// <summary> /// Parses a control from the specified <paramref name="obj"/>. /// </summary> /// <param name="area">The parent area of the control.</param> /// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param> public static GridControl Parse(GridArea area, JObject obj) { // Set basic properties GridControl control = new GridControl(obj) { Area = area }; Howdy.ReplaceEditorObjectFromConfig(control); // Parse the editor control.Editor = obj.GetObject("editor", x => GridEditor.Parse(control, x)); // Parse the control value JToken value = obj.GetValue("value"); foreach (IGridConverter converter in GridContext.Current.Converters) { try { IGridControlValue converted; if (!converter.ConvertControlValue(control, value, out converted)) { continue; } control.Value = converted; break; } catch (Exception ex) { global::Umbraco.Core.Composing.Current.Logger.Error <GridControl>(ex, "Converter of type " + converter + " failed for ConvertControlValue()"); } } return(control); }
/// <summary> /// Parses an editor from the specified <paramref name="control"/> and <paramref name="obj"/>. /// </summary> /// <param name="control">The parent control of the editor.</param> /// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param> public static GridEditor Parse(GridControl control, JObject obj) { // Parse basic properties GridEditor editor = new GridEditor(obj) { Control = control, Name = obj.GetString("name"), Alias = obj.GetString("alias"), View = obj.GetString("view"), Render = obj.GetString("render"), Icon = obj.GetString("icon") }; // Parse the editor configuration JToken config = obj.GetValue("config"); foreach (IGridConverter converter in GridContext.Current.Converters) { try { IGridEditorConfig converted; if (!converter.ConvertEditorConfig(editor, config, out converted)) { continue; } editor.Config = converted; break; } catch (Exception ex) { global::Umbraco.Core.Composing.Current.Logger.Error <GridEditor>(ex, "Converter of type " + converter + " failed for ConvertEditorConfig()"); } } return(editor); }
/// <summary> /// Parses a control from the specified <paramref name="obj"/>. /// </summary> /// <param name="area">The parent area of the control.</param> /// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param> public static GridControl Parse(GridArea area, JObject obj) { // Set basic properties GridControl control = new GridControl(obj) { Area = area }; // As of Umbraco 7.3, information about the editor is no longer saved in the JSON, since these should be read from the configuration if (UmbracoVersion.Current.Major == 7 && UmbracoVersion.Current.Minor >= 3) { Howdy.ReplaceEditorObjectFromConfig(control); } // Parse the editor control.Editor = obj.GetObject("editor", x => GridEditor.Parse(control, x)); // Parse the control value JToken value = obj.GetValue("value"); foreach (IGridConverter converter in GridContext.Current.Converters) { try { IGridControlValue converted; if (!converter.ConvertControlValue(control, value, out converted)) { continue; } control.Value = converted; break; } catch (Exception ex) { LogHelper.Error <GridControl>("Converter of type " + converter + " failed for ConvertControlValue()", ex); } } return(control); }