Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNTP returns IPublishedContent #24

Open
bjarnef opened this issue Oct 24, 2017 · 8 comments
Open

MNTP returns IPublishedContent #24

bjarnef opened this issue Oct 24, 2017 · 8 comments

Comments

@bjarnef
Copy link

bjarnef commented Oct 24, 2017

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.md

However I expirience it returns IPublishedContent, but it might be because the datatype instance is limited to select one item?
image

If I used one of the following, it sometimes returned null even a node was picked.

var pageTest1 = item.GetValue<IEnumerable<IPublishedContent>>("linkToPage");
var pageTest2 = (item.GetValue<IEnumerable<IPublishedContent>>("linkToPage") ?? Enumerable.Empty<IPublishedContent>()).FirstOrDefault();

But it is a bit strange, because in some of the items (LeBlender), it works with cast to IEnumerable<IPublishedContent>

var pageTest1 = item.GetValue<IEnumerable<IPublishedContent>>("linkToPage");
var pageTest2 = item.GetValue<IPublishedContent>("linkToPage");

However for a country node, if I instead cast to IPublishedContent it does work.
image

We have also ModelsBuilder enabled and use Our.Umbraco.CoreValueConverters v3.1.3 on Umbraco v7.5.8

@bjarnef
Copy link
Author

bjarnef commented Oct 24, 2017

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()

@Jeavon
Copy link
Owner

Jeavon commented Oct 26, 2017

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

@Jeavon
Copy link
Owner

Jeavon commented Oct 26, 2017

I found it and I'm not sure why it does this and I'm guessing that's what's causing your issues....

https://github.com/Lecoati/LeBlender/blob/e11905f192a1cb733ec012404998ff74f0b56ca5/Src/Lecoati.LeBlender.Extension/Models/LeBlenderPropertyModel.cs#L49

@bjarnef
Copy link
Author

bjarnef commented Oct 26, 2017

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.

@Jeavon
Copy link
Owner

Jeavon commented Oct 26, 2017

@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...

@bjarnef
Copy link
Author

bjarnef commented Oct 31, 2017

@Jeavon maybe @soreng know more about this?

@Jeavon
Copy link
Owner

Jeavon commented Nov 8, 2017

@bjarnef did you create this issue on LeBlender somewhere?

@bjarnef
Copy link
Author

bjarnef commented Nov 8, 2017

@Jeavon I think it is related to this issue Lecoati/LeBlender#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants