public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object source, bool preview) { var baseSource = base.ConvertIntermediateToObject(owner, propertyType, cacheLevel, source, preview); if (!IsOnlyImagesDataType(propertyType.DataType)) { return(baseSource); } var imageType = _publishedModelFactory.MapModelType(ModelType.For(ImageTypeAlias)); if (!(baseSource is IEnumerable <IPublishedContent> mediaItems)) { return(baseSource != null && baseSource.GetType().Inherits(imageType) ? baseSource : null); } var images = _publishedModelFactory.CreateModelList(ImageTypeAlias); foreach (var mediaItem in mediaItems.Where(mi => mi.GetType().Inherits(imageType))) { images.Add(mediaItem); } return(images); }
public Type GetModelType(Guid contentTypeKey) { var publishedContentType = GetContentType(contentTypeKey); if (publishedContentType != null) { var modelType = ModelType.For(publishedContentType.Alias); return(_publishedModelFactory.MapModelType(modelType)); } return(typeof(IPublishedElement)); }
public Type GetModelType(Guid contentTypeKey) { var publishedContentCache = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot().Content; var publishedContentType = publishedContentCache.GetContentType(contentTypeKey); if (publishedContentType != null) { var modelType = ModelType.For(publishedContentType.Alias); return(_publishedModelFactory.MapModelType(modelType)); } return(typeof(IPublishedElement)); }