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

[release/2.0] Fix ContentPartFIeldDefinition Settings.ToObject Deserialization #16788

Merged
merged 8 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
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 @@ -13,7 +13,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<BooleanFieldSettings>("BooleanFieldSettings_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<BooleanFieldSettings>();
var settings = partFieldDefinition.GetSettings<BooleanFieldSettings>();

model.Hint = settings.Hint;
model.Label = settings.Label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<DateFieldSettings>("DateFieldSettings_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<DateFieldSettings>();
var settings = partFieldDefinition.GetSettings<DateFieldSettings>();

model.Hint = settings.Hint;
model.Required = settings.Required;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<DateTimeFieldSettings>("DateTimeFieldSettings_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<DateTimeFieldSettings>();
var settings = partFieldDefinition.GetSettings<DateTimeFieldSettings>();

model.Hint = settings.Hint;
model.Required = settings.Required;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<LinkFieldSettings>("LinkFieldSettings_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<LinkFieldSettings>();
var settings = partFieldDefinition.GetSettings<LinkFieldSettings>();

model.Hint = settings.Hint;
model.HintLinkText = settings.HintLinkText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<LocalizationSetContentPickerFieldSettings>("LocalizationSetContentPickerFieldSettings_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<LocalizationSetContentPickerFieldSettings>();
var settings = partFieldDefinition.GetSettings<LocalizationSetContentPickerFieldSettings>();

model.Hint = settings.Hint;
model.Required = settings.Required;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<NumericFieldSettings>("NumericFieldSettings_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<NumericFieldSettings>();
var settings = partFieldDefinition.GetSettings<NumericFieldSettings>();

model.Hint = settings.Hint;
model.Required = settings.Required;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<TextFieldSettings>("TextFieldSettings_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<TextFieldSettings>();
var settings = partFieldDefinition.GetSettings<TextFieldSettings>();

model.Hint = settings.Hint;
model.Required = settings.Required;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<TimeFieldSettings>("TimeFieldSettings_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<TimeFieldSettings>();
var settings = partFieldDefinition.GetSettings<TimeFieldSettings>();

model.Hint = settings.Hint;
model.Required = settings.Required;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<YoutubeFieldSettings>("YoutubeFieldSetting_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<YoutubeFieldSettings>();
var settings = partFieldDefinition.GetSettings<YoutubeFieldSettings>();

model.Height = model.Height != default ? model.Height : 315;
model.Width = model.Width != default ? model.Width : 560;
model.Hint = settings.Hint;
model.Label = settings.Label;
model.Height = settings.Height != default ? settings.Height : 315;
model.Width = settings.Width != default ? settings.Width : 560;
model.Required = settings.Required;
}).Location("Content");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<ContentPickerFieldElasticEditorSettings>("ContentPickerFieldElasticEditorSettings_Edit", async model =>
{
var settings = partFieldDefinition.Settings.ToObject<ContentPickerFieldElasticEditorSettings>();
var settings = partFieldDefinition.GetSettings<ContentPickerFieldElasticEditorSettings>();

model.Index = settings.Index;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<ContentPickerFieldLuceneEditorSettings>("ContentPickerFieldLuceneEditorSettings_Edit", async model =>
{
var settings = partFieldDefinition.Settings.ToObject<ContentPickerFieldLuceneEditorSettings>();
var settings = partFieldDefinition.GetSettings<ContentPickerFieldLuceneEditorSettings>();

model.Index = settings.Index;
model.Indices = (await _luceneIndexSettingsService.GetSettingsAsync()).Select(x => x.IndexName).ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<GeoPointFieldSettings>("GeoPointFieldSettings_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<GeoPointFieldSettings>();
var settings = partFieldDefinition.GetSettings<GeoPointFieldSettings>();

model.Hint = settings.Hint;
model.Required = settings.Required;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<TaxonomyFieldSettings>("TaxonomyFieldSettings_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<TaxonomyFieldSettings>();
var settings = partFieldDefinition.GetSettings<TaxonomyFieldSettings>();

model.Hint = settings.Hint;
model.Required = settings.Required;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti
{
return Initialize<TaxonomyFieldTagsEditorSettings>("TaxonomyFieldTagsEditorSettings_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<TaxonomyFieldTagsEditorSettings>();
var settings = partFieldDefinition.GetSettings<TaxonomyFieldTagsEditorSettings>();

model.Open = settings.Open;
}).Location("Content");
Expand Down
2 changes: 1 addition & 1 deletion src/docs/releases/2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ services.AddJsonDerivedTypeInfo<SqlQuery, Query>();
{
return Initialize<NumericFieldSettings>("NumericFieldSettings_Edit", model =>
{
var settings = partFieldDefinition.Settings.ToObject<NumericFieldSettings>();
var settings = partFieldDefinition.GetSettings<NumericFieldSettings>();
model.Hint = settings.Hint;
// ...
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using OrchardCore.ContentManagement.Metadata.Builders;
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.ContentTypes.Editors;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.DisplayManagement.Zones;

namespace OrchardCore.Tests.Modules.OrchardCore.ContentFields.Settings;

public class DisplayDriverTestHelper
{
public static ContentPartDefinition GetContentPartDefinition<TField>(Action<ContentPartFieldDefinitionBuilder> configuration)
{
return new ContentPartDefinitionBuilder()
.Named("SomeContentPart")
.WithField<TField>("SomeField", configuration)
.Build();
}

public static Task<ShapeResult> GetShapeResultAsync<TDriver>(IShapeFactory factory, ContentPartDefinition contentDefinition)
where TDriver : IContentPartFieldDefinitionDisplayDriver, new()
=> GetShapeResultAsync(factory, contentDefinition, new TDriver());

public static async Task<ShapeResult> GetShapeResultAsync(IShapeFactory factory, ContentPartDefinition contentDefinition, IContentPartFieldDefinitionDisplayDriver driver)
{
var partFieldDefinition = contentDefinition.Fields.First();

var partFieldDefinitionShape = await factory.CreateAsync("ContentPartFieldDefinition_Edit", () =>
ValueTask.FromResult<IShape>(new ZoneHolding(() => factory.CreateAsync("ContentZone"))));
partFieldDefinitionShape.Properties["ContentField"] = partFieldDefinition;

var editorContext = new BuildEditorContext(partFieldDefinitionShape, "", false, "", factory, null, null);

var result = await driver.BuildEditorAsync(partFieldDefinition, editorContext);
await result.ApplyAsync(editorContext);

return (ShapeResult)result;
}
}
Loading
Loading