public override IDictionary <string, PreValue> ConvertEditorToDb(IDictionary <string, object> editorValue, PreValueCollection currentValue) { if (editorValue.TryGetValue("embeddedContentConfig", out object value)) { List <IContentType> contentTypes = _contentTypeService.GetAllContentTypes().ToList(); EmbeddedContentConfigDisplay configDisplay = JsonConvert.DeserializeObject <EmbeddedContentConfigDisplay>(value.ToString()); var config = new EmbeddedContentConfig { EnableCollapsing = configDisplay.EnableCollapsing, EnableFiltering = configDisplay.EnableFiltering, DocumentTypes = from item in configDisplay.DocumentTypes let contentType = contentTypes.FirstOrDefault(x => x.Alias == item.DocumentTypeAlias) where contentType != null select new EmbeddedContentConfigDocumentType { AllowEditingName = item.AllowEditingName, DocumentTypeAlias = item.DocumentTypeAlias, Group = item.Group, MaxInstances = item.MaxInstances, NameTemplate = item.NameTemplate, SettingsTabKey = item.SettingsTab.HasValue ? contentType.CompositionPropertyGroups.FirstOrDefault(x => x.Id == item.SettingsTab)?.Key : null }, Groups = configDisplay.Groups, MaxItems = configDisplay.MaxItems, MinItems = configDisplay.MinItems }; editorValue["embeddedContentConfig"] = JsonConvert.SerializeObject(config); } return(base.ConvertEditorToDb(editorValue, currentValue)); }
public override IDictionary <string, object> ConvertDbToEditor(IDictionary <string, object> defaultPreVals, PreValueCollection persistedPreVals) { if (persistedPreVals.PreValuesAsDictionary.TryGetValue("embeddedContentConfig", out PreValue preValue) && false == string.IsNullOrEmpty(preValue.Value)) { List <IContentType> contentTypes = _contentTypeService.GetAllContentTypes().ToList(); EmbeddedContentConfig config = JsonConvert.DeserializeObject <EmbeddedContentConfig>(preValue.Value); var configDisplay = new EmbeddedContentConfigDisplay { EnableCollapsing = config.EnableCollapsing, EnableFiltering = config.EnableFiltering, DocumentTypes = from item in config.DocumentTypes let contentType = contentTypes.FirstOrDefault(x => x.Alias == item.DocumentTypeAlias) where contentType != null select new EmbeddedContentConfigDocumentTypeDisplay { AllowEditingName = item.AllowEditingName, Description = UmbracoDictionaryTranslate(contentType.Description), DocumentTypeAlias = item.DocumentTypeAlias, Group = item.Group, Icon = contentType.Icon, MaxInstances = item.MaxInstances, Name = UmbracoDictionaryTranslate(contentType.Name), NameTemplate = item.NameTemplate, SettingsTab = item.SettingsTabKey.HasValue ? contentType.CompositionPropertyGroups .FirstOrDefault(x => x.Key == item.SettingsTabKey)?.Id : null }, Groups = config.Groups, MaxItems = config.MaxItems, MinItems = config.MinItems }; preValue.Value = JsonConvert.SerializeObject(configDisplay); } return(base.ConvertDbToEditor(defaultPreVals, persistedPreVals)); }