From 6fd80320f8ff107a296dbe7adb8030194cda93a8 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Fri, 12 Jan 2024 10:29:39 -0800 Subject: [PATCH] Fix Display Name (#15080) Fix #15062 --- .../Builders/ContentPartDefinitionBuilder.cs | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Builders/ContentPartDefinitionBuilder.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Builders/ContentPartDefinitionBuilder.cs index b99c0c060c3..8a227601a68 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Builders/ContentPartDefinitionBuilder.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Builders/ContentPartDefinitionBuilder.cs @@ -62,7 +62,7 @@ public ContentPartDefinition Build() public ContentPartDefinitionBuilder Named(string name) { Name = name; - + return this; } @@ -73,7 +73,7 @@ public ContentPartDefinitionBuilder RemoveField(string fieldName) { _fields.Remove(existingField); } - + return this; } @@ -81,14 +81,14 @@ public ContentPartDefinitionBuilder RemoveField(string fieldName) public ContentPartDefinitionBuilder WithSetting(string name, string value) { _settings[name] = value; - + return this; } public ContentPartDefinitionBuilder MergeSettings(JObject settings) { _settings.Merge(settings, ContentBuilderSettings.JsonMergeSettings); - + return this; } @@ -105,7 +105,7 @@ public ContentPartDefinitionBuilder MergeSettings(JObject settings) var settingsToMerge = existingJObject.ToObject(); setting(settingsToMerge); _settings[typeof(T).Name] = JObject.FromObject(settingsToMerge, ContentBuilderSettings.IgnoreDefaultValuesSerializer); - + return this; } @@ -144,14 +144,19 @@ public ContentPartDefinitionBuilder WithField(string fieldName, Action(); + + if (string.IsNullOrEmpty(settings.DisplayName)) { // If there is no display name, let's use the field name by default. - configurer.WithDisplayName(fieldName); + settings.DisplayName = fieldName; + fieldDefinition.PopulateSettings(settings); } - - _fields.Add(configurer.Build()); - + + _fields.Add(fieldDefinition); + return this; } @@ -196,14 +201,19 @@ public async Task WithFieldAsync(string fieldName, var configurer = new FieldConfigurerImpl(existingField, _part); await configurationAsync(configurer); - - if (string.IsNullOrEmpty(existingField.DisplayName())) + + var fieldDefinition = configurer.Build(); + + var settings = fieldDefinition.GetSettings(); + + if (string.IsNullOrEmpty(settings.DisplayName)) { // If there is no display name, let's use the field name by default. - configurer.WithDisplayName(fieldName); + settings.DisplayName = fieldName; + fieldDefinition.PopulateSettings(settings); } - _fields.Add(configurer.Build()); + _fields.Add(fieldDefinition); return this; }