From 485c6cb6a1133d1855fea67a0e697b44ea6a6285 Mon Sep 17 00:00:00 2001 From: Tom Fulton Date: Tue, 27 May 2014 14:31:23 -0600 Subject: [PATCH 1/3] When using ValueConverters, pass along the Content Type - fixes #133 * Add new property HostContentType to make Properties aware of their content type * Adjust Dummy PropertyType to include the Content Type * Pass in Content Type from ValueConverter to Deserialization helper through new optional parameter * Populate the property's HostContentType via RetrieveAdditionalProperties * Make sure HostContentType isn't persisted Notes: In some cases, the Umbraco Core looks for pt.ContentType.Alias, which didn't exist previously in our Dummy PropertyType. This would also potentially cause an error if any PVC's do the same. To fix we now keep track of the Content Type that the Archetype exists on (determined in the ArchetypeValueConverter), and pass this along to our Dummy PropertyType (and thus to PVCs) Note we made the hostContentType an optional parameter as there's some cases where we won't know the content type (ie ConvertDbToEditor). This (shouldn't?) be an issue as these cases should never have a reason to call GetValue. --- .../Umbraco.Archetype/Extensions/ArchetypeHelper.cs | 8 +++++--- .../Umbraco.Archetype/Models/ArchetypePropertyModel.cs | 5 ++++- .../PropertyConverters/ArchetypeValueConverter.cs | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/Umbraco/Umbraco.Archetype/Extensions/ArchetypeHelper.cs b/app/Umbraco/Umbraco.Archetype/Extensions/ArchetypeHelper.cs index 1db4ea6..0d03f92 100644 --- a/app/Umbraco/Umbraco.Archetype/Extensions/ArchetypeHelper.cs +++ b/app/Umbraco/Umbraco.Archetype/Extensions/ArchetypeHelper.cs @@ -4,6 +4,7 @@ using Archetype.Models; using Newtonsoft.Json; using Umbraco.Core; using Umbraco.Core.Models; +using Umbraco.Core.Models.PublishedContent; namespace Archetype.Extensions { @@ -46,7 +47,7 @@ namespace Archetype.Extensions } } - internal Models.ArchetypeModel DeserializeJsonToArchetype(string sourceJson, int dataTypeId) + internal Models.ArchetypeModel DeserializeJsonToArchetype(string sourceJson, int dataTypeId, PublishedContentType hostContentType = null) { try { @@ -56,7 +57,7 @@ namespace Archetype.Extensions { // Get list of configured properties and their types and map them to the deserialized archetype model var preValue = GetArchetypePreValueFromDataTypeId(dataTypeId); - RetrieveAdditionalProperties(ref archetype, preValue); + RetrieveAdditionalProperties(ref archetype, preValue, hostContentType); } catch (Exception ex) { @@ -110,7 +111,7 @@ namespace Archetype.Extensions /// /// The Archetype to add the additional metadata to /// The configuration of the Archetype - private void RetrieveAdditionalProperties(ref Models.ArchetypeModel archetype, ArchetypePreValue preValue) + private void RetrieveAdditionalProperties(ref Models.ArchetypeModel archetype, ArchetypePreValue preValue, PublishedContentType hostContentType = null) { foreach (var fieldset in preValue.Fieldsets) { @@ -125,6 +126,7 @@ namespace Archetype.Extensions propertyInst.DataTypeGuid = property.DataTypeGuid.ToString(); propertyInst.DataTypeId = GetDataTypeByGuid(property.DataTypeGuid).Id; propertyInst.PropertyEditorAlias = property.PropertyEditorAlias; + propertyInst.HostContentType = hostContentType; } } } diff --git a/app/Umbraco/Umbraco.Archetype/Models/ArchetypePropertyModel.cs b/app/Umbraco/Umbraco.Archetype/Models/ArchetypePropertyModel.cs index cd3b1ff..66773df 100644 --- a/app/Umbraco/Umbraco.Archetype/Models/ArchetypePropertyModel.cs +++ b/app/Umbraco/Umbraco.Archetype/Models/ArchetypePropertyModel.cs @@ -25,6 +25,9 @@ namespace Archetype.Models [JsonProperty("dataTypeGuid")] internal string DataTypeGuid { get; set; } + [JsonProperty("hostContentType")] + internal PublishedContentType HostContentType { get; set; } + public T GetValue() { @@ -80,7 +83,7 @@ namespace Archetype.Models private PublishedPropertyType CreateDummyPropertyType(int dataTypeId, string propertyEditorAlias) { - return new PublishedPropertyType(null, + return new PublishedPropertyType(this.HostContentType, new PropertyType(new DataTypeDefinition(-1, propertyEditorAlias) { Id = dataTypeId diff --git a/app/Umbraco/Umbraco.Archetype/PropertyConverters/ArchetypeValueConverter.cs b/app/Umbraco/Umbraco.Archetype/PropertyConverters/ArchetypeValueConverter.cs index 96b59c3..4f82c22 100644 --- a/app/Umbraco/Umbraco.Archetype/PropertyConverters/ArchetypeValueConverter.cs +++ b/app/Umbraco/Umbraco.Archetype/PropertyConverters/ArchetypeValueConverter.cs @@ -40,7 +40,8 @@ namespace Archetype.PropertyConverters return defaultValue; var archetype = new ArchetypeHelper().DeserializeJsonToArchetype(source.ToString(), - (propertyType != null ? propertyType.DataTypeId : -1)); + (propertyType != null ? propertyType.DataTypeId : -1), + (propertyType != null ? propertyType.ContentType : null)); return archetype; } From a9dc79e4ff5babdf3f92a919e7a3c1b32a4e47d1 Mon Sep 17 00:00:00 2001 From: Tom Fulton Date: Tue, 27 May 2014 15:01:21 -0600 Subject: [PATCH 2/3] Ensure new HostContentType isn't persisted --- app/Umbraco/Umbraco.Archetype/Models/ArchetypeModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Umbraco/Umbraco.Archetype/Models/ArchetypeModel.cs b/app/Umbraco/Umbraco.Archetype/Models/ArchetypeModel.cs index 1587050..b057aee 100644 --- a/app/Umbraco/Umbraco.Archetype/Models/ArchetypeModel.cs +++ b/app/Umbraco/Umbraco.Archetype/Models/ArchetypeModel.cs @@ -31,7 +31,7 @@ namespace Archetype.Models internal string SerializeForPersistence() { var json = JObject.Parse(JsonConvert.SerializeObject(this)); - var propertiesToRemove = new String[] { "propertyEditorAlias", "dataTypeId", "dataTypeGuid" }; + var propertiesToRemove = new String[] { "propertyEditorAlias", "dataTypeId", "dataTypeGuid", "hostContentType" }; json.Descendants().OfType() .Where(p => propertiesToRemove.Contains(p.Name)) From ba6921fdb98e1d04442393a192d832ec6942e484 Mon Sep 17 00:00:00 2001 From: Kevin Giszewski Date: Thu, 29 May 2014 17:50:43 -0400 Subject: [PATCH 3/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e15a4e1..efb7919 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ Archetype ========= ![alt tag](http://imulus.github.io/Archetype/images/logo.png) +![alt tag](http://imulus.github.io/Archetype/images/example1.png) + ## Installation Install the selected release through the Umbraco package installer or via NuGet.