Ejemplo n.º 1
0
        /// <summary>
        /// Gets the first link item from the <see cref="LinkPickerList"/> of the property with the specified
        /// <paramref name="propertyAlias"/>.
        ///
        /// If the property isn't a link picker (or the list is empty), an empty item
        /// will be returned instead. You can use the <see cref="LinkPickerItem.IsValid"/> property to check whether
        /// the returned item is valid.
        /// </summary>
        /// <param name="content">The published content to read the property from.</param>
        /// <param name="propertyAlias">The alias of the property.</param>
        /// <returns>An instance of <see cref="LinkPickerItem"/>.</returns>
        public static LinkPickerItem GetLinkPickerItem(this IPublishedContent content, string propertyAlias)
        {
            LinkPickerList list = content.GetPropertyValue(propertyAlias) as LinkPickerList;
            LinkPickerItem item = list?.Items.FirstOrDefault();

            return(item ?? new LinkPickerItem());
        }
        public GridControlCtaValue(GridControl control) : base(control)
        {
            var blenderCtrl = GridControlLeBlenderValue.Parse(control);

            if (blenderCtrl == null || blenderCtrl.Items == null)
            {
                return;
            }
            var item = blenderCtrl.Items.First();

            Headline = item.GetRawValue("headline");

            Text = item.GetRawValue("text");

            Link = !string.IsNullOrEmpty(item.GetRawValue("link"))
                                ? LinkPickerList.Parse(JObject.Parse(item.GetRawValue("link"))).Items.FirstOrDefault()
                                : null;
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            // Skip if the reader is not at the start of an object
            if (reader.TokenType != JsonToken.StartObject)
            {
                return(null);
            }

            // Load JObject from stream
            JObject obj = JObject.Load(reader);

            switch (objectType.FullName)
            {
            case "Skybrud.LinkPicker.LinkPickerList":
                return(LinkPickerList.Parse(obj));

            case "Skybrud.LinkPicker.LinkPickerItem":
                return(LinkPickerItem.Parse(obj));

            default:
                return(null);
            }
        }