コード例 #1
0
        public override object GetField(Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            var sitecoreGalleryField = new LinkField(field);
            var advancedGallery      = new AdvancedImageGalleryField();

            var stringValue = sitecoreGalleryField.Value.IsNullOrEmpty() ? "<gallery />" : sitecoreGalleryField.Value;

            var xml = new XmlDocument();

            xml.LoadXml(stringValue);
            var gallery       = xml.DocumentElement;
            var galleryImages = new List <AdvancedImageField>();

            if (gallery != null && gallery.HasChildNodes)
            {
                foreach (XmlElement galleryChildNode in gallery.ChildNodes)
                {
                    var img = AdvancedImageHelper.ConvertMediaItemToField(galleryChildNode, field.Database);
                    if (img == null)
                    {
                        continue;
                    }

                    galleryImages.Add(img);
                }
            }

            advancedGallery.GalleryItems = galleryImages;
            return(advancedGallery);
        }
        public override object GetField(Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            var sitecoreImage = new ImageField(field);
            var defaultImage  = new AdvancedImageField();

            if (sitecoreImage.Value.IsEmptyOrNull())
            {
                return(defaultImage);
            }

            var xml = new XmlDocument();

            xml.LoadXml(sitecoreImage.Value);

            var resultImage = AdvancedImageHelper.ConvertMediaItemToField(xml.DocumentElement, field.Database);

            return(resultImage ?? defaultImage);
        }