Skip to content

Commit

Permalink
Fix Display Name (#15080)
Browse files Browse the repository at this point in the history
Fix #15062
  • Loading branch information
MikeAlhayek authored Jan 12, 2024
1 parent 8852c98 commit 6fd8032
Showing 1 changed file with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ContentPartDefinition Build()
public ContentPartDefinitionBuilder Named(string name)
{
Name = name;

return this;
}

Expand All @@ -73,22 +73,22 @@ public ContentPartDefinitionBuilder RemoveField(string fieldName)
{
_fields.Remove(existingField);
}

return this;
}

[Obsolete("Use WithSettings<T>. This will be removed in a future version.")]
public ContentPartDefinitionBuilder WithSetting(string name, string value)
{
_settings[name] = value;

return this;
}

public ContentPartDefinitionBuilder MergeSettings(JObject settings)
{
_settings.Merge(settings, ContentBuilderSettings.JsonMergeSettings);

return this;
}

Expand All @@ -105,7 +105,7 @@ public ContentPartDefinitionBuilder MergeSettings(JObject settings)
var settingsToMerge = existingJObject.ToObject<T>();
setting(settingsToMerge);
_settings[typeof(T).Name] = JObject.FromObject(settingsToMerge, ContentBuilderSettings.IgnoreDefaultValuesSerializer);

return this;
}

Expand Down Expand Up @@ -144,14 +144,19 @@ public ContentPartDefinitionBuilder WithField(string fieldName, Action<ContentPa

configuration(configurer);

if (string.IsNullOrEmpty(existingField.DisplayName()))
var fieldDefinition = configurer.Build();

var settings = fieldDefinition.GetSettings<ContentPartFieldSettings>();

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;
}

Expand Down Expand Up @@ -196,14 +201,19 @@ public async Task<ContentPartDefinitionBuilder> 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<ContentPartFieldSettings>();

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;
}
Expand Down

0 comments on commit 6fd8032

Please sign in to comment.