umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
Other
4.49k stars 2.69k forks source link

V8: Media Picker Image Only Broken #5582

Closed UnsungHeros closed 5 years ago

UnsungHeros commented 5 years ago

When extending Image by composition and a media picker is configured to only allow images there is a conversion error when trying to iterate through a list of the custom image type.

Reproduction

When creating a custom Media Type 'RotatingImage' and composing it so that all the Image Mediatype Properties are available, I am unable to strongly type my custom Media Type with Allow only images configured.

Specifics

Steps to reproduce

install attached package. Allow the ImageRotatorlisting as a root element Add a Media Type called RotatingImage Add a custom property called alt as a text area Add a custom property called ImageLink as MultiUrl Picker that is min:1 max:1 Add a custom property OpenInNewwindow as a checkbox Go to the ImageRotator DocumentType and set it to pick multiple Items and pick only images Update your models Add and image rotatorlisting to the root named test. save and publish Create an imageRotator called Blue and add 3 images. +Create a new folder called test +Select the imagerotator media type when prompted +Select the 3 images Save and publish

Expected result

I would expect the images to show up. Unchecking the box to allow only images in the Multimedia picker will allow the images to show up as expected.

Actual result

A yellow screen which denotes The value "Umbraco.Web.PublishedModels.RotatingImage" is not of type "Umbraco.Web.PublishedModels.Image" and cannot be used in this generic collection. Parameter name: value

Side Note: I tried including the custom media type in the package[#5581].

MediaPicker_Image_Only_Broken_1.0.0.zip

nul800sebastiaan commented 5 years ago

This looks like a misunderstanding as to how ModelsBuilder works, making a composition doesn't necessarily mean ModelsBuilder will turn this into an inherited class. I would recommend you try and get some help with this on our forums at https://our.umbraco.com

If you drop a link to a forum here then @zpqrtbnk could have a look at it too to explain better.

bkclerke commented 5 years ago

I'm not sure about the install package listed above, but just a general trying to get a media picker to output an image on the site does seem to throw the error "The value "Umbraco.Web.PublishedModels.Image" is not of type "Umbraco.Web.PublishedModels.Image" and cannot be used in this generic collection. Parameter name: value".

I have a media picker on v8.0.2 that is only configured as a single media picker with "pick only images" selected and trying to output the image gives me the error with the following code. var node = Model.Value<IPublishedContent>("image");

I wonder if this issue is in relation to this thread on the forum? I was able to touch the web.config and the error went away and the image loaded but I'm not sure if that will happen every time there is a change? Seems like something might be off here.

balintbako commented 5 years ago

Same here. The problem is using Custom Media Types in Media Picker when "Pick only images" is on.

The error occurs even if you are adding Image as composition to it. The model builder is implementing IImage when you use Image for composition in your custom media type. Which is expected however the document type is using the Image class in the generic enumeration and not the interface when you use image picker and select image only.

bkclerke commented 5 years ago

@balintbako this issue was closed, do you think its worth opening a new issue with the description that you've provided to describe it? I am still having this issue on v 8.1. The i've setup an "image picker" that is a media picker with "pick only images" set and it throws the error. It's also affecting my nested content items from loading that have the image picker on there. Things that are only text work, but the image error is giving me problems.

cgarveyie commented 4 years ago

I don't think this should have been closed. The Use Case is entirely predictable and repeatable (happened to me on an up to date Umbraco 8 Cloud project last night). This is a bug and I suggest you disable the "Pick only images" switch until the problem is resolved.