Closed leekelleher closed 7 years ago
Thanks @leekelleher, feel free to merge it unless you want a sanity check ;)
@kgiszewski It's one of those itches that I'd been wanting to scratch since doing the IPublishedContent code, but never got around to it (until last night). I don't have a need for it myself (yet), all my code is currently based on ArchetypeModel, and as far as I'm aware no one has requested this. So yeah, just me scratching an itch.
I haven't done any end-to-end/integration testing with it.
I guess the main question is, do we think this is useful?
It's hard for me to say. I haven't done much with Umbraco in quite some time. For my purposes, I've always only needed the var items = Model.Content.GetPropertyValue<ArchetypeModel>myArchetypeAlias");
form.
I'd say if you don't have a direct need for this yet, it may behoove us to wait to merge but keep this PR here unless it's pretty much a transparent set of changes.
We haven't really done much with the code in awhile (good thing IMHO), so I've grown rather indifferent on the current landscape of Umbraco Core vs Archetype.
Maybe @kjac has an opinion :)
@leekelleher @kgiszewski I had a look at the PR and it looks pretty clean. And yes, it makes sense. Property retrieval is always mentioned as the culprit of working with Archetype for non-coders that are used to (read: have been forced to use) IPublishedContent
.
I will pull the PR and try it out locally, then I'll get back to you. Thanks, @leekelleher 👍
Woo! (I'd totally forgot about this one... oops! :relaxed:)
Added a TypeConverter for both
ArchetypeModel
andArchetypeFieldsetModel
, so that they can be converted to theirIPublishedContent
equivalent.Example usage would be, when you would typically do this...
You can now do this...
I know it seems more verbose, but the idea is that this could be hot-swappable with other property-editors, such as Nested Content. The frontend/code would deal purely with
IPublishedContent
objects.Also included unit-tests that run via Umbraco Core's
TryConvertTo
extension method, (which is whatContent.GetPropertyValue<T>
uses internally in Umbraco).There's a small caveat with the TypeConverter for
ArchetypeFieldsetModel
, I had to explicitly rejecttypeof(string)
, otherwise the JSON deserializer fails (inArchetypeHelper.DeserializeJsonToArchetype
). All other unit-tests still pass.