Comments (14)
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.
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.
@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.
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.
@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.
@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.
@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.
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.
from umbraco-ditto.
@leekelleher certainly can! https://gist.github.com/jamiepollock/67c52e5533a5a0aa084f
from umbraco-ditto.
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.
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.
That answer looks sound to me. Great work guys 👍
from umbraco-ditto.
I'm gonna close this one off. @mattbrailsford I agree about the PVC usage.
from umbraco-ditto.
Related Issues (20)
- DittoCache examples HOT 2
- Changes to lazy properties HOT 7
- Documentation using GitHub Pages HOT 2
- How to bind my model with an action to a DitFloView PartialView HOT 22
- UmbracoPicker returns wrong IPublishedContent in Umbraco 7.5.3 HOT 7
- Base Processor - exposing Umbraco context services HOT 5
- Custom Processor Contexts only persist a single .As() HOT 18
- Ditto Factory misusing `PluginManager.ResolveTypes`? HOT 10
- Ability to Conditionally Stop Processor Chain HOT 24
- XPath Processor? HOT 6
- Decimal mapping always 0 for negative values HOT 7
- Constructor Cache is no longer used HOT 3
- Orphaned Archetype Properties Cause Null Exception During Mapping HOT 3
- Migration to UMCO HOT 1
- Ditto-centric Stack Trace HOT 4
- Ditto processor attributes require a DittoProcessorMetaData attribute to be applied to the class but none was found. HOT 36
- Support for Umbraco v8 HOT 1
- Getting EntryPointNotFoundException on ditto objects HOT 2
- Excessive memory usage HOT 9
- Casting IPublishedContent to specific Model using Ditto mixing up property values between nodes on the same level HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from umbraco-ditto.