ReplaceEditorObjectFromConfig() public static method

public static ReplaceEditorObjectFromConfig ( GridControl control ) : void
control GridControl
return void
        /// <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);
        }
Esempio n. 2
0
        /// <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);
        }