コード例 #1
0
        /// <summary>
        /// Converts the specified <paramref name="token"/> into an instance of <see cref="IGridControlValue"/>.
        /// </summary>
        /// <param name="control">The parent control.</param>
        /// <param name="token">The instance of <see cref="JToken"/> representing the control value.</param>
        /// <param name="value">The converted value.</param>
        public virtual bool ConvertControlValue(GridControl control, JToken token, out IGridControlValue value)
        {
            value = null;

            switch (control.Editor.Alias)
            {
            case "media":
                value = GridControlMediaValue.Parse(control, token as JObject);
                break;

            case "embed":
                value = GridControlEmbedValue.Parse(control, token);
                break;

            case "rte":
                value = GridControlRichTextValue.Parse(control, token);
                break;

            case "macro":
                value = GridControlMacroValue.Parse(control, token as JObject);
                break;

            case "headline":
            case "quote":
                value = GridControlTextValue.Parse(control, token);
                break;
            }

            return(value != null);
        }
コード例 #2
0
        /// <summary>
        /// Converts the specified <paramref name="token"/> into an instance of <see cref="IGridControlValue"/>.
        /// </summary>
        /// <param name="control">The parent control.</param>
        /// <param name="token">The instance of <see cref="JToken"/> representing the control value.</param>
        /// <param name="value">The converted value.</param>
        public virtual bool ConvertControlValue(GridControl control, JToken token, out IGridControlValue value)
        {
            value = null;

            if (IsEmbedEditor(control.Editor))
            {
                value = GridControlEmbedValue.Parse(control, token);
            }
            else if (IsMacroEditor(control.Editor))
            {
                value = GridControlMacroValue.Parse(control, token as JObject);
            }
            else if (IsMediaEditor(control.Editor))
            {
                value = GridControlMediaValue.Parse(control, token as JObject);
            }
            else if (IsRichTextEditor(control.Editor))
            {
                value = GridControlRichTextValue.Parse(control, token);
            }
            else if (IsTextStringEditor(control.Editor))
            {
                value = GridControlTextValue.Parse(control, token);
            }

            return(value != null);
        }
コード例 #3
0
        protected virtual IGridControlValue ParseGridControlMediaValue(GridControl control, JObject json)
        {
            GridControlMediaValue value = new GridControlMediaValue(control, json);

            if (value.Id > 0 && _umbracoContextAccessor.TryGetUmbracoContext(out IUmbracoContext context))
            {
                value.PublishedImage = context.Media.GetById(value.Id);
            }

            return(value);
        }
コード例 #4
0
        public static string GetGridText(string content)
        {
            GridDataModel grid = GridDataModel.Deserialize(content);

            StringBuilder combined = new StringBuilder();

            foreach (GridControl ctrl in grid.GetAllControls())
            {
                switch (ctrl.Editor.Alias)
                {
                case "rte":
                {
                    // Get the HTML value
                    string html = ctrl.GetValue <GridControlRichTextValue>().Value;

                    // Strip any HTML tags so we only have text
                    string text = Regex.Replace(html, "<.*?>", "");

                    // Extra decoding may be necessary
                    text = HttpUtility.HtmlDecode(text);

                    // Now append the text
                    combined.AppendLine(text);

                    break;
                }

                case "media":
                {
                    GridControlMediaValue media = ctrl.GetValue <GridControlMediaValue>();
                    if (media != null)
                    {
                        combined.AppendLine(media.Caption);
                    }
                    break;
                }

                case "headline":
                case "quote":
                {
                    combined.AppendLine(ctrl.GetValue <GridControlTextValue>().Value);
                    break;
                }
                }
            }

            return(combined.ToString());
        }
コード例 #5
0
        private object GetMediaValue(GridControlMediaValue value)
        {
            // Just return null if the value is null
            if (value == null)
            {
                return(null);
            }

            // Get the media from the cache (and return null if not found)
            IPublishedContent media = UmbracoContext.Current.MediaCache.GetById(value.Id);

            if (media == null)
            {
                return(null);
            }

            return(new
            {
                id = media.Id,
                url = media.Url,
                cropUrl = media.GetCropUrl().SupportWebP(),
                name = media.Name
            });
        }
コード例 #6
0
        /// <summary>
        /// Converts the specified <paramref name="token"/> into an instance of <see cref="IGridControlValue"/>.
        /// </summary>
        /// <param name="control">The parent control.</param>
        /// <param name="token">The instance of <see cref="JToken"/> representing the control value.</param>
        /// <param name="value">The converted value.</param>
        public bool ConvertControlValue(GridControl control, JToken token, out IGridControlValue value)
        {
            value = null;

            switch (control.Editor.Alias)
            {
            case "media_wide":
            case "media_wide_cropped":
                value = GridControlMediaValue.Parse(control, token as JObject);
                break;

            case "banner_headline":
            case "banner_tagline":
            case "headline_centered":
            case "abstract":
            case "paragraph":
            case "quote_D":
            case "code":
                value = GridControlTextValue.Parse(control, token);
                break;
            }

            return(value != null);
        }