dawoe / OEmbed-Picker-Property-Editor

Property editor for Umbraco CMS to allow embedding 3rd party media like Youtube, Vimeo, ... outside of the rich text editor.
https://our.umbraco.org/projects/backoffice-extensions/oembed-picker-property-editor/
MIT License
10 stars 10 forks source link

modelsbuilder throws exception when property is optional #11

Closed ribsdigital closed 3 years ago

ribsdigital commented 3 years ago

hi @dawoe just installed the newest version of the plugin in a new site - lookin good!

one issue i have ran into though is that if a property is not marked as mandatory the models builder blows up...

this is the doctype set up:

image

if i select a video, everything works fine - if i leave the property empty, the class generated by the models builder throws the following exception when attempting to view a page that uses the model:

image

could this be an issue in the OEmbedPickerValueConverter property converter?

cheers,

jake

dawoe commented 3 years ago

Hi @ribsdigital

I will try to have a look at this today.

Dave

dawoe commented 3 years ago

Hi @ribsdigital

I tried to reproduce this, but I can't get this error.

Can you show me the code in your view ?

This is what I have

 @if(Model.SingleVideo != null)
        {
             @Model.SingleVideo.EmbedCode 
        }

Dave

ribsdigital commented 3 years ago

hi @dawoe thanks for getting back to me 👍

i did some more digging and i think i've found the issue. if we use the property in a regular doctype, there's no problem, we can do the null check in an if statement and everything works as expected.

however, we're using your package in conjunction with the https://our.umbraco.com/packages/backoffice-extensions/bento-editor/ package and that's when the exception occurs...

so i downloaded the property editor and dropped it into the project so i could debug - the issue seems to be on this line of the OEmbedPickerValueConverter property converter class:

if (inter == null)
{
    return allowMultipe ? Enumerable.Empty<OEmbedItem>() : null;
}

in a regular doctype, the inter property returns as null if a video hasn't been picked. but when it goes through bento, it returns as an empty string...

so i changed the code to this and it now works as expected:

if (string.IsNullOrWhiteSpace(inter?.ToString()))
{
    return allowMultipe ? Enumerable.Empty<OEmbedItem>() : null;
}

just pushed this up as a pull request ;)

https://github.com/dawoe/OEmbed-Picker-Property-Editor/pull/12

khraibani commented 3 years ago

Hi @dawoe I am having the issue as well, any chance to get release a version with the fix? Thank you for the package!

dawoe commented 3 years ago

Just released version 4.3.0 that contains this fix