Giter VIP home page Giter VIP logo

Comments (14)

mattbrailsford avatar mattbrailsford commented on July 28, 2024

Very interesting question. I'm wondering if this could actually fall into the realms of being an Umbraco Property Value Converter? which raises the question, at what point do we recommend PVC's over VR's?

It feels to me like if all you wanna do is change the type coming from UmbracoProperty, this could be when we suggest PVC's, although within Umbraco, these are global and can't be declared on a per mapping basis. I wonder though if within the MNTP PVC you can't detect what the type requested in the conversion is, and if it's just IPublishedContent then do a .FirstOrDefault on the list?

I do mix the use of PVC's when using Ditto, but I've never really given it thought on when to recommend them over VR's.

Wadda you think?

from umbraco-ditto.

leekelleher avatar leekelleher commented on July 28, 2024

A custom PVC makes sense. It gets the value in the format that you want it, at the correct part of the pipeline. I agree that ValueResolvers are more appropriate when you have no (or little) control over the PVC.

The only downside I recall is that the code to replace it can be a pain in the backside. But I haven't tried it recently, (it might have been improved?)


With regards to adding an overloaded constructor to UmbracoPropertyAttribute, I like that we can make it extensible. What do you think @mattbrailsford?

from umbraco-ditto.

mattbrailsford avatar mattbrailsford commented on July 28, 2024

@leekelleher I'm undecided, as it could open it up to abuse, depending on where we say you should draw the line.

If we are in agreement that the PVC should be the right place, I don't think this issue is a strong enough argument to say open it up yet so I'd be tempted to leave it until a more compelling one comes along?

from umbraco-ditto.

mattbrailsford avatar mattbrailsford commented on July 28, 2024

My gut feeling is, if it's coming from a single umbraco property, then UmbracoPropertyAttribute along with PVC's should be used. VR's should be used if the value is calculated, or resolved from multiple locations, or a non-umbraco location? In these scenarios, there should be no need to inherit the UmbracoPropertyAttribute/Resovler.

from umbraco-ditto.

JimBobSquarePants avatar JimBobSquarePants commented on July 28, 2024

@jamiepollock What happens in this case if you add a TypeConverterAtrribute assigning the DittoPickerConverter to the property? If any TypeConvrters are used Ditto will check to see if you are expecting a single generic TypeParam and return that instead of an enumerable collection. It also does the reverse.

This should solve your issue without the need for extra code.

from umbraco-ditto.

leekelleher avatar leekelleher commented on July 28, 2024

@JimBobSquarePants - @jamiepollock mentions on his original form post about using a custom TypeConverter, he wants to get the single IPublishedContent prior to that.

Although this does suggest that a post-conversion-handler could be used?

So many options!

from umbraco-ditto.

JimBobSquarePants avatar JimBobSquarePants commented on July 28, 2024

@leekelleher The question begs then.. @jamiepollock what extra behaviour is required in your converter that DittoPickerConverter doesn't already offer? It should handle converting to any Enumerable or single item from any of the built in pickers.

Yeah So many options!

from umbraco-ditto.

jamiepollock avatar jamiepollock commented on July 28, 2024

Hey gents, thanks for the open discussion on this matter. Looking at the original use case, I wouldn't want anything implemented which could be open to abuse.

@JimBobSquarePants I guess there isn't anything a DittoPickerConverter couldn't do, that's the desired behaviour I'm looking for. My only question is how do I use that?

from umbraco-ditto.

leekelleher avatar leekelleher commented on July 28, 2024

from umbraco-ditto.

jamiepollock avatar jamiepollock commented on July 28, 2024

@leekelleher certainly can! https://gist.github.com/jamiepollock/67c52e5533a5a0aa084f

from umbraco-ditto.

jamiepollock avatar jamiepollock commented on July 28, 2024

The code above is a general TypeConverter when dealing with multiple items. This code is based on stuff that predates custom Value Resolvers.

from umbraco-ditto.

leekelleher avatar leekelleher commented on July 28, 2024

I replied on the forum: https://our.umbraco.org/projects/developer-tools/ditto/ditto-feedback/71581-ienumerableipublishedcontent-to-single-ipublishedcontent-dittovalueresolver-or-typeconverter#230029

from umbraco-ditto.

JimBobSquarePants avatar JimBobSquarePants commented on July 28, 2024

That answer looks sound to me. Great work guys 👍

from umbraco-ditto.

leekelleher avatar leekelleher commented on July 28, 2024

I'm gonna close this one off. @mattbrailsford I agree about the PVC usage.

from umbraco-ditto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.