Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hey@all,
is there an easier way to create a new property like nested content programmatically?
I tried a little bit with the DataTypeService, but i think there is a way, easier than creating a lot of nested objects.
I think a little example would be very helpful.
var dataType = new DataType(new DataEditor(new DebugDiagnosticsLogger())); var existingDataType = new DataType(dataType.Editor); existingDataType.Level = customDataType.Level; existingDataType.Path = customDataType.Path; existingDataType.CreateDate = customDataType.CreateDate; existingDataType.CreatorId = customDataType.CreatorId; existingDataType.DeleteDate = customDataType.DeleteDate; existingDataType.ParentId = customDataType.ParentId; existingDataType.SortOrder = customDataType.SortOrder; existingDataType.UpdateDate = customDataType.UpdateDate; existingDataType.Key = customDataType.Key; existingDataType.Name = customDataType.Name; if(customDataType.EditorAlias.Equals("Umbraco.NestedContent")) existingDataType.Editor = new NestedContentPropertyEditor(null, new Lazy<PropertyEditorCollection>()); if(customDataType.EditorAlias.Equals("Umbraco.NestedContent")) existingDataType.Configuration = new Umbraco.Web.PropertyEditors.NestedContentConfiguration() { ConfirmDeletes = customDataType.Configuration.ConfirmDeletes ?? false, ContentTypes = customDataType.Configuration.ContentTypes.Select(c => new Umbraco.Web.PropertyEditors.NestedContentConfiguration.ContentType() { Alias = c.ncAlias, Template = c.nameTemplate, TabAlias = c.ncTabAlias }).ToArray(), HideLabel = customDataType.Configuration.HideLabel ?? false, MaxItems = customDataType.Configuration.MaxItems, MinItems = customDataType.Configuration.MinItems, ShowIcons = customDataType.Configuration.ShowIcons ?? true };
Solution
var editor = propertyEditors.FirstOrDefault<IDataEditor>((IDataEditor x) => x.Alias == customDataType.EditorAlias); var existingDataType = services.DataTypeService.GetAll().FirstOrDefault(d => d.Key.Equals(customDataType.Key)); if (existingDataType == null) { existingDataType = new DataType(editor) { Name = customDataType.Name }; }
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Create DataType programmitcally Umbraco V8.5.2
Hey@all,
is there an easier way to create a new property like nested content programmatically?
I tried a little bit with the DataTypeService, but i think there is a way, easier than creating a lot of nested objects.
I think a little example would be very helpful.
Solution
is working on a reply...