umco / umbraco-tuple

[UNRELEASED] Tuple property-editor for Umbraco 7+
MIT License
1 stars 4 forks source link

Compatibility with Dropdown data type #3

Closed dnwhte closed 5 years ago

dnwhte commented 5 years ago

Hello,

I know this package isn't being actively developed, but I'm wondering if you could give me some direction on making it work with the built in Dropdown data type?

I am getting this error whenever a dropdown is used.

[InvalidCastException: Unable to cast object of type 'System.String' to type 'System.String[]'.]
   Umbraco.Core.PropertyEditors.ValueConverters.FlexibleDropdownPropertyValueConverter.ConvertSourceToObject(PublishedPropertyType propertyType, Object source, Boolean preview) +61
   Our.Umbraco.Tuple.ValueConverters.TupleValueConverter.ConvertSourceToObject(PublishedPropertyType propertyType, Object source, Boolean preview) +285
   Our.Umbraco.PropertyList.ValueConverters.PropertyListValueConverter.ConvertSourceToObject(PublishedPropertyType propertyType, Object source, Boolean preview) +225

Any direction would be much appreciated.

Thanks

leekelleher commented 5 years ago

Hi @dnwhte!

I've had a quick look at what might be happening here, and it looks that the issue might be this line...

https://github.com/umco/umbraco-tuple/blob/develop/src/Our.Umbraco.Tuple/ValueConverters/TupleValueConverter.cs#L77-L79

...where it's trying to convert the inner property value (from ConvertDataToSource) to the ClrType.

Which in the case of FlexibleDropdownPropertyValueConverter, that would be a string...

https://github.com/umbraco/Umbraco-CMS/blob/release-7.15.3/src/Umbraco.Core/PropertyEditors/ValueConverters/FlexibleDropdownPropertyValueConverter.cs#L64

...but the ConvertDataToSource method has literally just returned a string[]...

https://github.com/umbraco/Umbraco-CMS/blob/release-7.15.3/src/Umbraco.Core/PropertyEditors/ValueConverters/FlexibleDropdownPropertyValueConverter.cs#L31-L36

...so Tuple code doesn't cast/convert it to the correct type, so when the subsequent ConvertSourceToObject calls are made, it's the wrong type.

That's my (educated) guess at least - I haven't tested this out.


Are you building/running Tuple from source? Would you be willing to try out modifying these lines?

https://github.com/umco/umbraco-tuple/blob/develop/src/Our.Umbraco.Tuple/ValueConverters/TupleValueConverter.cs#L77-L79

It'd be to ignore the TryConvertTo bit and set the itemSource value directly.

e.g.

item.Value = itemSource;
dnwhte commented 5 years ago

👍 it works!

leekelleher commented 5 years ago

@dnwhte Cool. (phew!) I'll close off this ticket. Feel free to send over a PR whenever you have time. 👍

dnwhte commented 5 years ago

Will submit a PR.

Because I don't fully understand how this is working, is this a reliable solution or just a band-aid?

leekelleher commented 5 years ago

It's reliable, previously it was a bug. That method should return the "source" values, not the end target "object types".