diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/DashboardPartContentTypeDefinitionHandler.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/DashboardPartContentTypeDefinitionHandler.cs index e95d9f77b56..626dee7b357 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/DashboardPartContentTypeDefinitionHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Services/DashboardPartContentTypeDefinitionHandler.cs @@ -7,9 +7,13 @@ namespace OrchardCore.AdminDashboard.Services; -public sealed class DashboardPartContentTypeDefinitionHandler : ContentDefinitionHandlerBase +public sealed class DashboardPartContentTypeDefinitionHandler : IContentDefinitionHandler { - public override void ContentTypeBuilding(BuildingContentTypeContext context) + /// + /// Adds the to the content type definition when the stereotype is set to 'DashboardWidget'. + /// This occurs during the content type building process, allowing the content type to function as a dashboard widget. + /// + public void ContentTypeBuilding(BuildingContentTypeContext context) { if (!context.Record.Settings.TryGetPropertyValue(nameof(ContentTypeSettings), out var node)) { @@ -36,13 +40,17 @@ public override void ContentTypeBuilding(BuildingContentTypeContext context) { [nameof(ContentSettings)] = JObject.FromObject(new ContentSettings { - IsCodeManaged = true, + IsSystemType = true, }), }, }); } - public override void ContentTypePartBuilding(ContentTypePartContextBuilding context) + /// + /// Marks the part on the content type as a system type to prevent its removal. + /// This ensures that the part remains integral to the content type and cannot be deleted. + /// + public void ContentTypePartBuilding(ContentTypePartContextBuilding context) { if (!context.Record.PartName.EqualsOrdinalIgnoreCase(nameof(DashboardPart))) { @@ -52,12 +60,16 @@ public override void ContentTypePartBuilding(ContentTypePartContextBuilding cont var settings = context.Record.Settings[nameof(ContentSettings)]?.ToObject() ?? new ContentSettings(); - settings.IsCodeManaged = true; + settings.IsSystemType = true; context.Record.Settings[nameof(ContentSettings)] = JObject.FromObject(settings); } - public override void ContentPartDefinitionBuilding(ContentPartDefinitionContextBuilding context) + /// + /// Creates a definition if the Record is null and the part name is 'DashboardPart'. + /// This ensures that the 'DashboardPart' has a valid definition when it is missing. + /// + public void ContentPartDefinitionBuilding(ContentPartDefinitionContextBuilding context) { if (context.Record is not null || context.Name != nameof(DashboardPart)) { @@ -76,9 +88,13 @@ public override void ContentPartDefinitionBuilding(ContentPartDefinitionContextB }), [nameof(ContentSettings)] = JObject.FromObject(new ContentSettings { - IsCodeManaged = true, + IsSystemType = true, }), }, }; } + + public void ContentPartFieldBuilding(ContentPartFieldContextBuilding context) + { + } } diff --git a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Startup.cs b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Startup.cs index 2c8044282b4..fe2b3c48103 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminDashboard/Startup.cs @@ -43,7 +43,7 @@ public override void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddDataMigration(); - services.AddScoped(); + services.AddScoped(); } public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/ContentDefinitionService.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/ContentDefinitionService.cs index 96b5a31be6b..ac31afee411 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/ContentDefinitionService.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Services/ContentDefinitionService.cs @@ -216,11 +216,9 @@ public async Task RemovePartFromTypeAsync(string partName, string typeName) var settings = partDefinition.GetSettings(); - if (settings.IsCodeManaged) + if (settings.IsSystemType) { - _logger.LogError("The part '{PartName}' is code managed and cannot be removed from '{ContentType}' content type.", partName, typeName); - - throw new InvalidOperationException("Unable to remove code managed part."); + throw new InvalidOperationException("Unable to remove system-type part."); } await _contentDefinitionManager.AlterTypeDefinitionAsync(typeName, typeBuilder => typeBuilder.RemovePart(partName)); @@ -228,7 +226,7 @@ public async Task RemovePartFromTypeAsync(string partName, string typeName) var context = new ContentPartDetachedContext { ContentTypeName = typeName, - ContentPartName = partName + ContentPartName = partName, }; _contentDefinitionEventHandlers.Invoke((handler, ctx) => handler.ContentPartDetached(ctx), context, _logger); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Admin/Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Admin/Edit.cshtml index 67cd6dd4bde..42ba09e0ec3 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Admin/Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Views/Admin/Edit.cshtml @@ -128,7 +128,7 @@
@T["Edit"] - @if (!settings.IsCodeManaged) + @if (!settings.IsSystemType) { @T["Remove"] } @@ -165,7 +165,7 @@
-