umbraco / Umbraco.UIBuilder.Issues

Back office UI builder for Umbraco
3 stars 2 forks source link

the 'entity picker' doesn't appear to be using the value converter #13

Closed ribsdigital closed 2 years ago

ribsdigital commented 2 years ago

Describe the bug the 'entity picker' doesn't appear to be using the value converter as the type in the generated models builder class is object not IEnumerable<object> as described in the documentation https://docs.getkonstrukt.net/extras/property-editors/entity-picker#getting-the-value-of-an-entity-picker

Steps To Reproduce Steps to reproduce the behavior:

  1. add a new datatype based on the Konstrukt Entity Picker and configure it to talk to a entity image
  2. add the datatype to a property on a doctype: image
  3. pick items on the node in the content tree: image
  4. view the property type in the generated models builder file: image

Expected behavior an IEnumerable<object> type in the generated model

Environment (please complete the following information):

Additional context would it also be possible to give the code path to the property value converter as we need to call the ConvertIntermediateToObject method in another area of the backend code?

mattbrailsford commented 2 years ago

@ribsdigital Konstrukt doesn't have anything to do with Models Builder and nor does it run Value Converters. Konstrukt simply uses property editors as a mechanism for editing a POCO model. What is persisted in the database is what you get access to on your POCO model. If you need to change that to another format, you need to use Value Mappers https://docs.getkonstrukt.net/api/value-mappers

pgregorynz commented 2 years ago

Hey @mattbrailsford I think you might have misunderstood the issue. In your documentation in the Extras section, you have a page about Entity Pickers which can be put on doctypes to pick entities from the Database and at the end of that page you have section: https://docs.getkonstrukt.net/extras/property-editors/entity-picker#getting-the-value-of-an-entity-picker


Getting the value of an entity picker

The entity picker property editor comes with a built in value converter meaning that whenever you retrieve the property value from Umbraco it will return the actual selected entities.

// Example
foreach(var p in Model.Content.People.Cast<Person>()){
    ...
}

Note: Due to the fact that the property editor can link to any entity type, the returned value type from the value converter will be IEnumerable<object> and so will require the entities to be cast to the desired concrete type.


The issue that @ribsdigital is facing is that we don't get an IEnumerable back. We only get a Object.

It appears that maybe the builtin valueconverter you mention is not working / is not registered / doesnt exist, and therefore when when we try to retreive the values we get Object. That Object only contains a comma delimited list of Database Entity IDs.

The other thing is that the example is in an Umbraco 8 format? Model.Content So we are wondering if this this documentation section is a hangover from Fluidity? And if so, is it expected that the developer needs to write their own valueConverter now? Or should there be one?

mattbrailsford commented 2 years ago

@pgregorynz doh! My bad, you're right, I totally misunderstood the question.

You are also right that the value converter appeared to be missing. I must have forgotten about it in the port over.

I've gone an implemented it now on a 1.0.3 unstable build if you want to try it. The nice thing in v9, I can even tell models builder the expected type so it will already be cast to the right entity type (I've updated the docs accordingly).

Give it a try and let me know if it resolves your issue.

ribsdigital commented 2 years ago

hi @mattbrailsford we're having a bit of trouble installing the build, visual studio can't seem to find it on the nuget feed...

was there any hypens ect in the package name?

mattbrailsford commented 2 years ago

Have you enabled the nuget option to allow installing pre-releases?

ribsdigital commented 2 years ago

hi @mattbrailsford weird... it wasn't happy via the package manager console but it's fine via 'manage packages' 😕

but yup, all good - the converter kicks in and we now get an IEnumerable<People>:

image

happy days 👍