public override async Task ActivatingAsync(ActivatingContentContext context) { // This method is called on New() // Adds all the parts to a content item based on the content type definition. var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType); if (contentTypeDefinition == null) { return; } foreach (var typePartDefinition in contentTypeDefinition.Parts) { var partName = typePartDefinition.PartDefinition.Name; // We create the part from it's known type or from a generic one var part = _contentPartFactory.GetTypeActivator(partName).CreateInstance(); var partHandlers = _contentPartHandlerResolver.GetHandlers(partName); await partHandlers.InvokeAsync((handler, context, part) => handler.ActivatingAsync(context, part), context, part, _logger); // TODO: This can be removed in a future release as the recommended way is to use ContentOptions. // Iterate existing handler registrations as multiple handlers maybe not be registered with ContentOptions. await _partHandlers.InvokeAsync((handler, context, part) => handler.ActivatingAsync(context, part), context, part, _logger); context.ContentItem.Weld(typePartDefinition.Name, part); foreach (var partFieldDefinition in typePartDefinition.PartDefinition.Fields) { var fieldName = partFieldDefinition.Name; if (!part.Has(fieldName)) { var fieldActivator = _contentFieldFactory.GetTypeActivator(partFieldDefinition.FieldDefinition.Name); part.Weld(fieldName, fieldActivator.CreateInstance()); } } } }
public override async Task ActivatingAsync(ActivatingContentContext context) { // This method is called on New() // Adds all the parts to a content item based on the content type definition. var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType); if (contentTypeDefinition == null) { return; } foreach (var typePartDefinition in contentTypeDefinition.Parts) { var partName = typePartDefinition.PartDefinition.Name; // We create the part from it's known type or from a generic one var part = _contentPartFactory.GetTypeActivator(partName).CreateInstance(); var partHandlers = _contentPartHandlerResolver.GetHandlers(partName); await partHandlers.InvokeAsync((handler, context, part) => handler.ActivatingAsync(context, part), context, part, _logger); context.ContentItem.Weld(typePartDefinition.Name, part); foreach (var partFieldDefinition in typePartDefinition.PartDefinition.Fields) { var fieldName = partFieldDefinition.Name; if (!part.Has(fieldName)) { var fieldActivator = _contentFieldFactory.GetTypeActivator(partFieldDefinition.FieldDefinition.Name); part.Weld(fieldName, fieldActivator.CreateInstance()); } } } }