From 951c1a2080b7691422dec104bd2688d7124226b4 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Mon, 23 Oct 2023 15:07:14 -0700 Subject: [PATCH] Assign the technical name of the field as the display name by default Fix #14570 --- .../Builders/ContentPartDefinitionBuilder.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Builders/ContentPartDefinitionBuilder.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Builders/ContentPartDefinitionBuilder.cs index 0a0424bb6c1..d343767417b 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Builders/ContentPartDefinitionBuilder.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Builders/ContentPartDefinitionBuilder.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement.Metadata.Models; +using OrchardCore.ContentManagement.Metadata.Settings; using OrchardCore.ContentManagement.Utilities; namespace OrchardCore.ContentManagement.Metadata.Builders @@ -123,6 +124,11 @@ public ContentPartDefinitionBuilder WithField(string fieldName) public ContentPartDefinitionBuilder WithField(string fieldName, Action configuration) { + if (string.IsNullOrWhiteSpace(fieldName)) + { + throw new ArgumentException($"'{nameof(fieldName)}' cannot be null or empty."); + } + var existingField = _fields.FirstOrDefault(x => string.Equals(x.Name, fieldName, StringComparison.OrdinalIgnoreCase)); if (existingField != null) { @@ -137,6 +143,9 @@ public ContentPartDefinitionBuilder WithField(string fieldName, Action WithFieldAsync(string fieldName, Func configurationAsync) { + if (string.IsNullOrWhiteSpace(fieldName)) + { + throw new ArgumentException($"'{nameof(fieldName)}' cannot be null or empty."); + } + var existingField = _fields.FirstOrDefault(x => string.Equals(x.Name, fieldName, StringComparison.OrdinalIgnoreCase)); if (existingField != null) @@ -160,6 +174,9 @@ public async Task WithFieldAsync(string fieldName, } var configurer = new FieldConfigurerImpl(existingField, _part); + // Assume that the display name is the same as the field name. + // Set the display name before invoking the given action, to allow the action to set the display-name explicitly. + configurer.WithDisplayName(fieldName); await configurationAsync(configurer);