Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign the technical name of the field as the display name by default #14571

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -123,6 +124,11 @@ public ContentPartDefinitionBuilder WithField(string fieldName)

public ContentPartDefinitionBuilder WithField(string fieldName, Action<ContentPartFieldDefinitionBuilder> 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)
{
Expand All @@ -137,13 +143,21 @@ public ContentPartDefinitionBuilder WithField(string fieldName, Action<ContentPa
existingField = new ContentPartFieldDefinition(null, fieldName, new JObject());
}
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);
configuration(configurer);
_fields.Add(configurer.Build());
return this;
}

public async Task<ContentPartDefinitionBuilder> WithFieldAsync(string fieldName, Func<ContentPartFieldDefinitionBuilder, Task> 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)
Expand All @@ -160,6 +174,9 @@ public async Task<ContentPartDefinitionBuilder> 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);

Expand Down
Loading