From f52bbc2d0aff43bb0b1a6eaee02be8d6f53d37e2 Mon Sep 17 00:00:00 2001 From: Tom Fulton Date: Thu, 24 Apr 2014 22:39:22 -0600 Subject: [PATCH] Extract methods to retrieve metadata not stored in the model --- .../Extensions/ArchetypeHelper.cs | 68 ++++++++++++------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/app/Umbraco/Umbraco.Archetype/Extensions/ArchetypeHelper.cs b/app/Umbraco/Umbraco.Archetype/Extensions/ArchetypeHelper.cs index 6d5a0f8..8484202 100644 --- a/app/Umbraco/Umbraco.Archetype/Extensions/ArchetypeHelper.cs +++ b/app/Umbraco/Umbraco.Archetype/Extensions/ArchetypeHelper.cs @@ -38,23 +38,7 @@ namespace Archetype.Umbraco.Extensions { // Get list of configured properties and their types and map them to the deserialized archetype model var preValue = GetArchetypePreValueFromDataTypeId(dataTypeId); - foreach (var fieldset in preValue.Fieldsets) - { - var fieldsetAlias = fieldset.Alias; - foreach (var fieldsetInst in archetype.Fieldsets.Where(x => x.Alias == fieldsetAlias)) - { - foreach (var property in fieldset.Properties) - { - var propertyAlias = property.Alias; - foreach ( - var propertyInst in fieldsetInst.Properties.Where(x => x.Alias == propertyAlias)) - { - propertyInst.DataTypeId = GetDataTypeByGuid(property.DataTypeGuid).Id; - propertyInst.PropertyEditorAlias = property.PropertyEditorAlias; - } - } - } - } + RetrieveAdditionalProperties(ref archetype, preValue); } catch (Exception ex) { @@ -81,14 +65,7 @@ namespace Archetype.Umbraco.Extensions : preValues.PreValuesAsArray.First().Value; var config = JsonConvert.DeserializeObject(configJson, _jsonSettings); - - foreach (var fieldset in config.Fieldsets) - { - foreach (var property in fieldset.Properties) - { - property.PropertyEditorAlias = GetDataTypeByGuid(property.DataTypeGuid).PropertyEditorAlias; - } - } + RetrieveAdditionalProperties(ref config); return config; @@ -102,5 +79,46 @@ namespace Archetype.Umbraco.Extensions () => _app.Services.DataTypeService.GetDataTypeDefinitionById(guid)); } + /// + /// Retrieves additional metadata that isn't available on the stored model of an Archetype + /// + /// The Archetype to add the additional metadata to + /// The configuration of the Archetype + private void RetrieveAdditionalProperties(ref Models.Archetype archetype, ArchetypePreValue preValue) + { + foreach (var fieldset in preValue.Fieldsets) + { + var fieldsetAlias = fieldset.Alias; + foreach (var fieldsetInst in archetype.Fieldsets.Where(x => x.Alias == fieldsetAlias)) + { + foreach (var property in fieldset.Properties) + { + var propertyAlias = property.Alias; + foreach ( var propertyInst in fieldsetInst.Properties.Where(x => x.Alias == propertyAlias)) + { + propertyInst.DataTypeId = GetDataTypeByGuid(property.DataTypeGuid).Id; + propertyInst.PropertyEditorAlias = property.PropertyEditorAlias; + } + } + } + } + } + + /// + /// Retrieves additional metadata that isn't available on the stored model of an ArchetypePreValue + /// + /// The Archetype to add the additional metadata to + /// The configuration of the Archetype + private void RetrieveAdditionalProperties(ref Models.ArchetypePreValue preValue) + { + foreach (var fieldset in preValue.Fieldsets) + { + foreach (var property in fieldset.Properties) + { + property.PropertyEditorAlias = GetDataTypeByGuid(property.DataTypeGuid).PropertyEditorAlias; + } + } + } + } }