Open bjarnef opened 6 years ago
My original code used
var page = (item.GetValue<IEnumerable<IPublishedContent>>("linkToPage") ?? Enumerable.Empty<IPublishedContent>()).FirstOrDefault();
It did work for some items, but was sometimes returning null.
If I change my code to the following it seems to work.
var linkToPage1 = item.GetValue<IEnumerable<IPublishedContent>>("linkToPage");
var linkToPage2 = item.GetValue<IPublishedContent>("linkToPage");
var page = (linkToPage1 ?? linkToPage2.AsEnumerableOfOne()).FirstOrDefault()
Hi @bjarnef
That's really odd (and wrong), I would guess it has something to do what's going on inside GetValue, I'm guessing this method is from LeBlender?
Jeavon
I found it and I'm not sure why it does this and I'm guessing that's what's causing your issues....
Hi @Jeavon
Yes it is a bit strange, it does seems to work for some of the LeBlender items. For now I solved it by using the following:
var linkToPage1 = item.GetValue<IEnumerable<IPublishedContent>>("linkToPage");
var linkToPage2 = item.GetValue<IPublishedContent>("linkToPage");
//var page = (item.GetValue<IEnumerable<IPublishedContent>>("linkToPage") ?? Enumerable.Empty<IPublishedContent>()).FirstOrDefault();
// fix issue with property value converter sometimes returns IPublishedContent, sometimes IEnumerable<IPublishedContent>
var page = (linkToPage1 ?? linkToPage2.AsEnumerableOfOne()).FirstOrDefault();
I have also had some issues in some of the (LeBlender) grid editors, when casting an json object to a string
or the object/model directly, e.g. for LinkPicker package. https://our.umbraco.org/projects/backoffice-extensions/link-picker/
//var link = selector.GetValue<string>("link");
//var link = selector.GetValue<LinkPickerModel>("link");
var link = selector.GetRawValue("link");
LinkPickerModel linkPage = null;
if (link != null)
{
linkPage = JsonConvert.DeserializeObject<LinkPickerModel>(link);
}
but I don't have these issues in projects without property value converter package. The properties linkToPage
and link
are both using LinkPicker as datatype.
@bjarnef it's because of that code within the GetValue method of LeBlender, it is sometimes returning "Source" and sometimes returning "Object", it should always return "Object". I can't think of reason why this would be like this perhaps @agiraud might know...
@Jeavon maybe @soreng know more about this?
@bjarnef did you create this issue on LeBlender somewhere?
@Jeavon I think it is related to this issue https://github.com/Lecoati/LeBlender/issues/80 although not exact same functionally, but an issue how the value is returned from LeBlender when using core property value converters mainly an issue with pickers.
In the docs it says that MNTP (Multinode Tree Picker) returns
IEnumerable<IPublishedContent>
https://github.com/Jeavon/Umbraco-Core-Property-Value-Converters/blob/v3/Docs/MultiNodeTreePicker.mdHowever I expirience it returns
IPublishedContent
, but it might be because the datatype instance is limited to select one item?If I used one of the following, it sometimes returned null even a node was picked.
But it is a bit strange, because in some of the items (LeBlender), it works with cast to
IEnumerable<IPublishedContent>
However for a country node, if I instead cast to
IPublishedContent
it does work.We have also ModelsBuilder enabled and use
Our.Umbraco.CoreValueConverters
v3.1.3 on Umbraco v7.5.8