public static void AlterTypeDefinition(this IContentDefinitionManager manager, string name, Action <ContentTypeDefinitionBuilder> alteration) { var typeDefinition = manager.LoadTypeDefinition(name) ?? new ContentTypeDefinition(name, name.CamelFriendly()); var builder = new ContentTypeDefinitionBuilder(typeDefinition); alteration(builder); manager.StoreTypeDefinition(builder.Build()); }
public static async Task AlterTypeDefinitionAsync(this IContentDefinitionManager manager, string name, Func <ContentTypeDefinitionBuilder, Task> alterationAsync) { var typeDefinition = manager.LoadTypeDefinition(name) ?? new ContentTypeDefinition(name, name.CamelFriendly()); var builder = new ContentTypeDefinitionBuilder(typeDefinition); await alterationAsync(builder); manager.StoreTypeDefinition(builder.Build()); }
public async Task <ActionResult> EditPOST(string id, EditTypeViewModel viewModel) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContentTypes)) { return(Forbid()); } var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition(id); if (contentTypeDefinition == null) { return(NotFound()); } viewModel.Settings = contentTypeDefinition.Settings; viewModel.TypeDefinition = contentTypeDefinition; viewModel.DisplayName = contentTypeDefinition.DisplayName; viewModel.Editor = await _contentDefinitionDisplayManager.UpdateTypeEditorAsync(contentTypeDefinition, _updateModelAccessor.ModelUpdater); if (!ModelState.IsValid) { _documentStore.Cancel(); return(View(viewModel)); } else { var ownedPartDefinition = _contentDefinitionManager.LoadPartDefinition(contentTypeDefinition.Name); if (ownedPartDefinition != null && viewModel.OrderedFieldNames != null) { _contentDefinitionService.AlterPartFieldsOrder(ownedPartDefinition, viewModel.OrderedFieldNames); } _contentDefinitionService.AlterTypePartsOrder(contentTypeDefinition, viewModel.OrderedPartNames); _notifier.Success(H["\"{0}\" settings have been saved.", contentTypeDefinition.Name]); } return(RedirectToAction("Edit", new { id })); }
public EditTypeViewModel LoadType(string name) { var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition(name); if (contentTypeDefinition == null) { return(null); } return(new EditTypeViewModel(contentTypeDefinition)); }
public void Uninstall() { //remove created attribute from Party Content Type var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Party"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Party", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); } }
// public int UpdateFrom1() // { // // // return 2; // } public void Uninstall() { //remove created attribute from DocumentLibrary,WorkDocument,SpreadSheet Content Type var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("SpreadSheet"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("SpreadSheet", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); } }
// public int UpdateFrom1() // { // // return 2; // } public void Uninstall() { //remove created attribute from Policy Content Type var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Policy"); if (contentTypeDefinition == null) { return; // NotFound(); } _contentDefinitionManager.AlterTypeDefinition("Policy", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); }
public async Task <IShape> UpdateEditorAsync(ContentItem contentItem, IUpdateModel updater, bool isNew, string groupId, string htmlFieldPrefix) { if (contentItem == null) { throw new ArgumentNullException(nameof(contentItem)); } var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition(contentItem.ContentType); if (contentTypeDefinition == null) { throw new NullReferenceException($"Content Type {contentItem.ContentType} does not exist."); } var stereotype = contentTypeDefinition.GetSettings <ContentTypeSettings>().Stereotype; var actualShapeType = (stereotype ?? "Content") + "_Edit"; var itemShape = await CreateContentShapeAsync(actualShapeType); itemShape.Properties["ContentItem"] = contentItem; itemShape.Properties["Stereotype"] = stereotype; // adding an alternate for [Stereotype]_Edit__[ContentType] e.g. Content-Menu.Edit itemShape.Metadata.Alternates.Add(actualShapeType + "__" + contentItem.ContentType); var context = new UpdateEditorContext( itemShape, groupId, isNew, htmlFieldPrefix, _shapeFactory, await _layoutAccessor.GetLayoutAsync(), new ModelStateWrapperUpdater(updater) ); await BindPlacementAsync(context); var updateContentContext = new UpdateContentContext(contentItem); await _contentHandlers.InvokeAsync((handler, updateContentContext) => handler.UpdatingAsync(updateContentContext), updateContentContext, _logger); await _handlers.InvokeAsync((handler, contentItem, context) => handler.UpdateEditorAsync(contentItem, context), contentItem, context, _logger); await _contentHandlers.Reverse().InvokeAsync((handler, updateContentContext) => handler.UpdatedAsync(updateContentContext), updateContentContext, _logger); return(context.Shape); }
Task IFeatureEventHandler.EnabledAsync(IFeatureInfo feature) { if (feature.Id == "Intelli.WorkBooks.SpreadSheets") { //reset created attribute for SpreadSheet, WorkDocument var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("SpreadSheet"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("SpreadSheet", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } } return(Task.CompletedTask); }
Task IFeatureEventHandler.EnabledAsync(IFeatureInfo feature) { if (feature.Id == "Intelli.Parties") { //reset created attribute for Party var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Party"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Party", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } } return(Task.CompletedTask); }
Task IFeatureEventHandler.EnabledAsync(IFeatureInfo feature) { if (feature.Id == "Intelli.GRC") { var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Policy"); if (contentTypeDefinition == null) { return(Task.CompletedTask);// NotFound(); } _contentDefinitionManager.AlterTypeDefinition("Policy", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } return(Task.CompletedTask); }
public async Task UpdateEditorAsync(ContentItem contentItem, UpdateEditorContext context) { var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition(contentItem.ContentType); if (contentTypeDefinition == null) { return; } var contentShape = context.Shape as IZoneHolding; var partsShape = await context.ShapeFactory.CreateAsync("ContentZone", Arguments.From(new { Identifier = contentItem.ContentItemId })); contentShape.Zones["Parts"] = partsShape; foreach (var displayDriver in _displayDrivers) { try { var result = await displayDriver.UpdateEditorAsync(contentItem, context); if (result != null) { await result.ApplyAsync(context); } } catch (Exception ex) { InvokeExtensions.HandleException(ex, _logger, displayDriver.GetType().Name, nameof(UpdateEditorAsync)); } } foreach (var typePartDefinition in contentTypeDefinition.Parts) { var partTypeName = typePartDefinition.PartDefinition.Name; var partName = typePartDefinition.Name; var contentType = typePartDefinition.ContentTypeDefinition.Name; var activator = _contentPartFactory.GetTypeActivator(partTypeName); var part = (ContentPart)contentItem.Get(activator.Type, partName) ?? activator.CreateInstance(); var partPosition = typePartDefinition.GetSettings <ContentTypePartSettings>().Position ?? "before"; part.ContentItem = contentItem; // Create a custom shape to render all the part shapes into it var typePartShapeResult = CreateShapeResult(context.GroupId, partTypeName, contentType, typePartDefinition, partPosition); await typePartShapeResult.ApplyAsync(context); var typePartShape = typePartShapeResult.Shape; if (typePartShape == null) { // Part is explicitly hidden in placement then stop rendering it continue; } typePartShape.Properties["ContentPart"] = part; typePartShape.Properties["ContentTypePartDefinition"] = typePartDefinition; partsShape.Properties[partName] = typePartShape; context.DefaultZone = $"Parts.{partName}:{partPosition}"; var partDisplayDrivers = _contentPartDisplayDriverResolver.GetEditorDrivers(partTypeName, typePartDefinition.Editor()); await partDisplayDrivers.InvokeAsync(async (driver, part, typePartDefinition, context) => { var result = await driver.UpdateEditorAsync(part, typePartDefinition, context); if (result != null) { await result.ApplyAsync(context); } }, part, typePartDefinition, context, _logger); foreach (var partFieldDefinition in typePartDefinition.PartDefinition.Fields) { var fieldName = partFieldDefinition.Name; var fieldPosition = partFieldDefinition.GetSettings <ContentPartFieldSettings>().Position ?? "before"; context.DefaultZone = $"Parts.{partName}:{fieldPosition}"; var fieldDisplayDrivers = _contentFieldDisplayDriverResolver.GetEditorDrivers(partFieldDefinition.FieldDefinition.Name, partFieldDefinition.Editor()); await fieldDisplayDrivers.InvokeAsync(async (driver, part, partFieldDefinition, typePartDefinition, context) => { var result = await driver.UpdateEditorAsync(part, partFieldDefinition, typePartDefinition, context); if (result != null) { await result.ApplyAsync(context); } }, part, partFieldDefinition, typePartDefinition, context, _logger); } } }
public async Task UpdateEditorAsync(ContentItem contentItem, UpdateEditorContext context) { var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition(contentItem.ContentType); if (contentTypeDefinition == null) { return; } dynamic contentShape = context.Shape; dynamic partsShape = await context.ShapeFactory.CreateAsync("ContentZone", Arguments.From(new { ContentItem = contentItem })); contentShape.Zones["Parts"] = partsShape; foreach (var displayDriver in _displayDrivers) { try { var result = await displayDriver.UpdateEditorAsync(contentItem, context); if (result != null) { await result.ApplyAsync(context); } } catch (Exception ex) { InvokeExtensions.HandleException(ex, Logger, displayDriver.GetType().Name, nameof(UpdateEditorAsync)); } } foreach (var typePartDefinition in contentTypeDefinition.Parts) { var partTypeName = typePartDefinition.PartDefinition.Name; var activator = _contentPartFactory.GetTypeActivator(partTypeName); var part = (ContentPart)contentItem.Get(activator.Type, typePartDefinition.Name) ?? activator.CreateInstance(); part.ContentItem = contentItem; // Create a custom shape to render all the part shapes into it dynamic typePartShape = await context.ShapeFactory.CreateAsync("ContentPart_Edit"); typePartShape.ContentPart = part; typePartShape.ContentTypePartDefinition = typePartDefinition; var partPosition = typePartDefinition.GetSettings <ContentTypePartSettings>().Position ?? "before"; partsShape.Add(typePartShape, partPosition); partsShape[typePartDefinition.Name] = typePartShape; context.DefaultZone = $"Parts.{typePartDefinition.Name}:{partPosition}"; var partDisplayDrivers = _contentPartDisplayDriverResolver.GetEditorDrivers(partTypeName, typePartDefinition.Editor()); await partDisplayDrivers.InvokeAsync(async (driver, part, typePartDefinition, context) => { var result = await driver.UpdateEditorAsync(part, typePartDefinition, context); if (result != null) { await result.ApplyAsync(context); } }, part, typePartDefinition, context, Logger); // TODO: This can be removed in a future release as the recommended way is to use ContentOptions. // Iteratate existing driver registrations as multiple drivers maybe not be registered with ContentOptions. await _partDisplayDrivers.InvokeAsync(async (driver, part, typePartDefinition, context) => { var result = await driver.UpdateEditorAsync(part, typePartDefinition, context); if (result != null) { await result.ApplyAsync(context); } }, part, typePartDefinition, context, Logger); foreach (var partFieldDefinition in typePartDefinition.PartDefinition.Fields) { var fieldName = partFieldDefinition.Name; var fieldPosition = partFieldDefinition.GetSettings <ContentPartFieldSettings>().Position ?? "before"; context.DefaultZone = $"Parts.{typePartDefinition.Name}:{fieldPosition}"; var fieldDisplayDrivers = _contentFieldDisplayDriverResolver.GetEditorDrivers(partFieldDefinition.FieldDefinition.Name, partFieldDefinition.Editor()); await fieldDisplayDrivers.InvokeAsync(async (driver, part, partFieldDefinition, typePartDefinition, context) => { var result = await driver.UpdateEditorAsync(part, partFieldDefinition, typePartDefinition, context); if (result != null) { await result.ApplyAsync(context); } }, part, partFieldDefinition, typePartDefinition, context, Logger); // TODO: This can be removed in a future release as the recommended way is to use ContentOptions. // Iteratate existing driver registrations as multiple drivers maybe not be registered with ContentOptions. await _fieldDisplayDrivers.InvokeAsync(async (driver, part, partFieldDefinition, typePartDefinition, context) => { var result = await driver.UpdateEditorAsync(part, partFieldDefinition, typePartDefinition, context); if (result != null) { await result.ApplyAsync(context); } }, part, partFieldDefinition, typePartDefinition, context, Logger); } } }
public void Uninstall() { //remove created attribute from Classroom Content Type var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Link"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Link", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Heading"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Heading", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("UnorderedList"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("UnorderedList", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("OrderedList"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("OrderedList", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Figure"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Figure", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Blockquote"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Blockquote", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Hero"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Hero", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Card"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Card", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Banner"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Banner", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Embed"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Embed", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = false); }); } }
Task IFeatureEventHandler.EnabledAsync(IFeatureInfo feature) { if (feature.Id == "Etch.OrchardCore.Widgets") { //reset created attribute for var contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Link"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Link", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Heading"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Heading", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("UnorderedList"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("UnorderedList", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("OrderedList"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("OrderedList", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Figure"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Figure", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Blockquote"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Blockquote", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Hero"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Hero", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Card"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Card", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Banner"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Banner", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } contentTypeDefinition = _contentDefinitionManager.LoadTypeDefinition("Embed"); if (contentTypeDefinition != null) { _contentDefinitionManager.AlterTypeDefinition("Embed", config => { config.MergeSettings <ContentTypeSettings>(x => x.Enabled = true); }); } } return(Task.CompletedTask); }