Comments (3)
I've added some crazy magic to all the value resolvers in one of my codebases recently. At it's core, it converts IPublishedContent(s) to strongly typed models, and also returns the type of the matched model from the value converter
Models builder uses that return type the next time models are generated, and it will generate strongly typed properties for all properties returning IPublishedContent(s), including nested content pickers (with a single doctype as the blueprint)
So automatically I get
///<summary>
/// Team Members
///</summary>
[ImplementPropertyType("teamMembers")]
public IEnumerable<Core.Models.Content.TeamMember> TeamMembers
{
get { return this.GetPropertyValue<IEnumerable<Core.Models.Content.TeamMember>>("teamMembers"); }
}
instead of
///<summary>
/// Team Members
///</summary>
[ImplementPropertyType("teamMembers")]
public IEnumerable<IPublishedContent> TeamMembers
{
get { return this.GetPropertyValue<IEnumerable<IPublishedContent>>("teamMembers"); }
}
It needs some refactoring and further testing before I share it (maybe as a PR), but in the meantime, this is what handles the model builder conversion
public IPublishedContent GetTypedModel<TModel>(IPublishedContent nestedContent) where TModel : PublishedContentModel
{
var factoryResolver = Umbraco.Core.Models.PublishedContent.PublishedContentModelFactoryResolver.Current;
if (factoryResolver?.HasValue == true)
{
return factoryResolver.Factory?.CreateModel(nestedContent) as TModel;
}
return nestedContent; // or throw an exception perhaps?
}
So I'd vote option 1, given that that factory resolver is in the core anyway. If a factory is configured you can handle the conversion in the value converter, and additionally return the correct strong type, to allow models builder to generate strongly typed nested content properties for free 😄
from umbraco-nested-content.
This is a ModelsBuilder related question. Looking at the implementation of OfType in core, it just does a simple "is" type check, so the model needs to already be of the given type.
Options could be 1) we support models builder and within the value converter convert the items to the respective types or 2) implement an OfType method of our own that simply create a models builder model for the given type.
I think option 1 would probably be the correct answer but would mean we'd have a dependency on MB
from umbraco-nested-content.
Closing this ticket, further details on #124 (comment)
from umbraco-nested-content.
Related Issues (20)
- Renamed document types are not resolved HOT 1
- Doc Types - Tab Drop Down List Not Saving When Setting Up New Data Type HOT 1
- Nested content not working inside doctype grid editor that is inside a Vorto editor HOT 6
- Featured Request : Deletion of Item Alert Message HOT 1
- Cannot add a new content if multiple document types have been specified HOT 8
- Cannot resolve NestedContent values for indexing due to UmbracoContext.Current == null HOT 1
- {{ pickerAlias | ncNodeName }} don't works with media picker HOT 6
- "Choose type of content" dialog always opens on top of the edit page HOT 5
- Review "Content Type selection" modal position
- Data type using nested content defaults to first tab in document type after save HOT 1
- Remove labels on nested property types HOT 1
- Performance - Nested content with RTE HOT 2
- Error saving content HOT 3
- How to render widget template on page template HOT 1
- Nested content title formatting with properties HOT 3
- Make obvious names for overview of the items inside the content HOT 2
- ncNodeName and ncMediaName not documented HOT 1
- Feature Request - Tabbed Interface HOT 1
- Add documentation for adding programmatically
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-nested-content.