Beispiel #1
0
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            if (string.IsNullOrEmpty(source?.ToString()))
            {
                return(null);
            }

            return(NestedContentHelper.ConvertFromNestedContent(JArray.Parse(source.ToString())));
        }
Beispiel #2
0
            public override string ConvertDbToString(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
            {
                if (string.IsNullOrEmpty(property.Value?.ToString()))
                {
                    return(string.Empty);
                }
                using (_profilingLogger.DebugDuration <EmbeddedContentPropertyEditor>($"ConvertDbToString({property.Alias})"))
                {
                    List <IContentType> contentTypes = _contentTypeService.GetAllContentTypes().ToList();
                    var items = new List <EmbeddedContentItem>();

                    JArray source = NestedContentHelper.ConvertFromNestedContent(JArray.Parse(property.Value.ToString()));

                    foreach (EmbeddedContentItem item in source.ToObject <EmbeddedContentItem[]>())
                    {
                        if (!item.Published)
                        {
                            continue;
                        }

                        IContentType contentType = contentTypes.FirstOrDefault(x => x.Alias == item.ContentTypeAlias);
                        if (contentType == null)
                        {
                            continue;
                        }
                        foreach (PropertyType propType in contentType.CompositionPropertyGroups.SelectMany(_ => _.PropertyTypes))
                        {
                            item.Properties.TryGetValue(propType.Alias, out object value);
                            PropertyEditor propertyEditor = _propertyEditorResolver.GetByAlias(propType.PropertyEditorAlias);

                            if (propertyEditor == null)
                            {
                                continue;
                            }

                            item.Properties[propType.Alias] = propertyEditor.ValueEditor.ConvertDbToString(
                                new Property(propType, value),
                                propType,
                                dataTypeService
                                );
                        }

                        items.Add(item);
                    }

                    if (items.Count == 0)
                    {
                        return(string.Empty);
                    }

                    return(JsonConvert.SerializeObject(items));
                }
            }
Beispiel #3
0
            public override object ConvertDbToEditor(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
            {
                if (string.IsNullOrEmpty(property.Value?.ToString()))
                {
                    return(new object[0]);
                }

                using (_profilingLogger.DebugDuration <EmbeddedContentPropertyEditor>($"ConvertDbToEditor({property.Alias})"))
                {
                    JArray source = NestedContentHelper.ConvertFromNestedContent(JArray.Parse(property.Value.ToString()));

                    List <IContentType> contentTypes = _contentTypeService.GetAllContentTypes().ToList();
                    PreValueCollection  preValues    = dataTypeService.GetPreValuesCollectionByDataTypeId(propertyType.DataTypeDefinitionId);

                    PreValue configPreValue = preValues.PreValuesAsDictionary["embeddedContentConfig"];
                    var      config         = JsonConvert.DeserializeObject <EmbeddedContentConfig>(configPreValue.Value);

                    var items = source.ToObject <EmbeddedContentItem[]>();

                    return((from indexedItem in items.Select((item, index) => new { item, index })
                            let item = indexedItem.item
                                       let index = indexedItem.index
                                                   let configDocType = config.DocumentTypes.FirstOrDefault(x => x.DocumentTypeAlias == item.ContentTypeAlias)
                                                                       where configDocType != null
                                                                       let contentType = contentTypes.FirstOrDefault(x => x.Alias == item.ContentTypeAlias)
                                                                                         let tabs = (from pg in contentType.CompositionPropertyGroups
                                                                                                     orderby pg.SortOrder
                                                                                                     group pg by pg.Name into groupedByTabName
                                                                                                     let firstTab = groupedByTabName.First()
                                                                                                                    let propertyTypes = groupedByTabName.SelectMany(x => x.PropertyTypes)
                                                                                                                                        select new TabWithKey <EmbeddedContentPropertyDisplay>()
                    {
                        Id = firstTab.Id,
                        Key = firstTab.Key,
                        Label = UmbracoDictionaryTranslate(firstTab.Name),
                        Alias = firstTab.Key.ToString(),
                        Properties = from pt in propertyTypes
                                     orderby pt.SortOrder
                                     let value = GetPropertyValue(item.Properties, pt.Alias)
                                                 let p = GetProperty(pt, value)
                                                         where p != null
                                                         select p
                    }).ToList()
                                                                                                    where contentType != null
                                                                                                    select new EmbeddedContentItemDisplay
                    {
                        Key = item.Key,
                        AllowEditingName = configDocType.AllowEditingName == "1",
                        ContentTypeAlias = item.ContentTypeAlias,
                        ContentTypeName = UmbracoDictionaryTranslate(contentType.Name),
                        Description = UmbracoDictionaryTranslate(contentType.Description),
                        CreateDate = item.CreateDate,
                        UpdateDate = item.UpdateDate,
                        CreatorId = item.CreatorId,
                        WriterId = item.WriterId,
                        Icon = contentType.Icon,
                        Name = item.Name,
                        Published = item.Published,
                        SettingsTab = configDocType.SettingsTabKey.HasValue ? tabs.FirstOrDefault(x => x.Key == configDocType.SettingsTabKey) : null,
                        Tabs = configDocType.SettingsTabKey.HasValue ? tabs.Where(x => x.Key != configDocType.SettingsTabKey) : tabs
                    }).ToList());
                }
            }