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

OSOE-818: Upgrade to Orchard Core 2.0 #180

Merged
merged 119 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 108 commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
dd5a144
Update NuGet versions to pre-release.
sarahelsaig Feb 22, 2024
8dfb784
Merge remote-tracking branch 'origin/dev' into issue/OSOE-795
sarahelsaig Feb 22, 2024
7928059
Fix compilation errors.
sarahelsaig Feb 23, 2024
4a90771
Refactor CodeGenerationDisplayDriver.
sarahelsaig Feb 23, 2024
87c3db9
Fix compilation errors.
sarahelsaig Feb 23, 2024
d9d5d9c
Remove "using Newtonsoft.Json"
sarahelsaig Feb 24, 2024
8186703
Fix MenuWidgetLiquidFilter.
sarahelsaig Feb 24, 2024
2c38547
Update OC to latest (because of bug fix for WorkflowTypeStep)
sarahelsaig Mar 3, 2024
22b85a4
ISmtpService is obsolete.
sarahelsaig Mar 3, 2024
c087456
Update method name.
sarahelsaig Mar 4, 2024
dc1d164
Update OC preview version.
sarahelsaig Mar 7, 2024
68c7cf5
Update code generation test due to change in serialization.
sarahelsaig Mar 13, 2024
4a695ab
Update OC package
sarahelsaig Mar 13, 2024
aec510e
Code cleanup.
sarahelsaig Mar 13, 2024
e6a3888
Use JObject.FromObject instead of JsonSerializer.SerializeToNode wher…
sarahelsaig Apr 2, 2024
3e72269
Merge remote-tracking branch 'origin/dev' into issue/OSOE-795
sarahelsaig Apr 22, 2024
f35bde3
Fix SerializeAndDeserialize
sarahelsaig Apr 23, 2024
bfd977f
Update OC preview version.
sarahelsaig Apr 23, 2024
33639b9
Update AddCondition to AddRuleCondition
sarahelsaig Apr 23, 2024
75b5863
Update OC package version.
sarahelsaig Apr 27, 2024
3416279
Merge remote-tracking branch 'origin/dev' into issue/OSOE-795
sarahelsaig May 4, 2024
547b55e
Update OC versions
sarahelsaig May 4, 2024
eadc295
Post merge and OC update fixup
sarahelsaig May 4, 2024
5800d7b
Update OC to the latest preview.
sarahelsaig May 7, 2024
0f74d1a
Rename variable.
sarahelsaig May 8, 2024
b3e7616
Replace strange leftover `var` with `const`.
sarahelsaig May 10, 2024
640cfc8
Merge pull request #161 from Lombiq/issue/OSOE-795
dministro May 15, 2024
f8ef8bb
Merge remote-tracking branch 'origin/dev' into task/system-text-json-…
sarahelsaig May 16, 2024
d3ceb3f
Merge remote-tracking branch 'origin/dev' into task/system-text-json-…
sarahelsaig May 28, 2024
1cf44a1
Update OC preview version.
sarahelsaig May 28, 2024
424fc91
Update OC preview version.
sarahelsaig May 30, 2024
916e0c3
Update OC preview version.
sarahelsaig Jun 5, 2024
208df5d
Merge remote-tracking branch 'origin/dev' into task/system-text-json-…
sarahelsaig Jun 14, 2024
c75c35d
Merge branch 'task/system-text-json-migration' into issue/OCC-245
sarahelsaig Jun 14, 2024
a5e5afc
Update OC version.
sarahelsaig Jun 18, 2024
198a812
Update OC version.
sarahelsaig Jun 19, 2024
eaf409b
Update OC preview version.
sarahelsaig Jun 20, 2024
bb92529
Update OC preview version.
sarahelsaig Jun 21, 2024
7373769
Merge remote-tracking branch 'origin/issue/OCC-245' into issue/OCC-245
sarahelsaig Jun 21, 2024
d863a02
Update HL and UITT NuGet versions.
sarahelsaig Jun 24, 2024
197fd92
Update OC NuGet versions.
sarahelsaig Jun 24, 2024
fbcd47a
Update to latest OC preview version.
sarahelsaig Jul 2, 2024
2cb7148
Update OC preview version.
sarahelsaig Jul 11, 2024
5c5d168
Merge remote-tracking branch 'origin/dev' into issue/OCC-245
sarahelsaig Jul 11, 2024
01ddf7f
Fix package consolidation.
sarahelsaig Jul 11, 2024
ab7a875
Merge remote-tracking branch 'origin/dev' into task/system-text-json-…
sarahelsaig Jul 12, 2024
2c05143
Merge remote-tracking branch 'origin/task/system-text-json-migration'…
sarahelsaig Jul 12, 2024
a9d0e60
Update HL version.
sarahelsaig Jul 13, 2024
38eb4a0
Update UITT version.
sarahelsaig Jul 13, 2024
af7f503
Use CreateModelMaybeAsync.
sarahelsaig Jul 14, 2024
92b464b
Update HL nuget version.
sarahelsaig Jul 16, 2024
b26c98c
Update all UITT Nuget versions.
sarahelsaig Jul 16, 2024
5610a0f
Update package version.
sarahelsaig Jul 16, 2024
5fe7a1f
Update OC preview versions.
sarahelsaig Jul 24, 2024
c382b33
Fix param.
sarahelsaig Jul 24, 2024
7de2d89
Update HL preview version.
sarahelsaig Jul 26, 2024
f19fc1f
Update UITT preview version.
sarahelsaig Jul 26, 2024
6e13d74
Update HL preview.
sarahelsaig Jul 27, 2024
ab0a7dc
Update UITT version.
sarahelsaig Jul 27, 2024
2d125a1
Update UITT preview version.
sarahelsaig Jul 27, 2024
b1fe33d
NuGet.config
sarahelsaig Jul 27, 2024
8dd7409
Update HL nuget version.
sarahelsaig Jul 27, 2024
00e2953
Update HL.
sarahelsaig Jul 27, 2024
60efcf6
OrchardCore.Email.Smtp instead of OrchardCore.Email.
sarahelsaig Jul 28, 2024
16eb73c
Merge pull request #170 from Lombiq/issue/OCC-245
Piedone Jul 28, 2024
af0f5de
Update OC preview version.
sarahelsaig Jul 29, 2024
66c5283
Update OC preview version again (sigh).
sarahelsaig Jul 30, 2024
3f312f6
Add Google Tag (shape, Liquid and Razor tag helpers).
sarahelsaig Aug 4, 2024
32e8bee
Update OC preview version.
sarahelsaig Aug 6, 2024
a7e1f24
Post-merge fixups.
sarahelsaig Aug 7, 2024
166a530
Use CreateModelAsync where applicable.
sarahelsaig Aug 7, 2024
5bb8abd
Update HL alpha version.
sarahelsaig Aug 7, 2024
6462de8
Update UITT alpha version.
sarahelsaig Aug 7, 2024
ae783c1
Update OC preview version.
sarahelsaig Aug 7, 2024
b165ab3
Update OC preview.
sarahelsaig Aug 8, 2024
b3575d6
Update new breaking changes.
sarahelsaig Aug 8, 2024
a379d58
Merge pull request #174 from Lombiq/issue/OSOE-893
sarahelsaig Aug 9, 2024
7ba77b0
Update HL alpha version.
sarahelsaig Aug 9, 2024
3679538
Update UITT alpha version.
sarahelsaig Aug 9, 2024
ebbdc42
Update OC previews.
sarahelsaig Aug 13, 2024
17e50cb
Merge branch 'task/system-text-json-migration' into issue/NEST-536
sarahelsaig Aug 13, 2024
1d44a13
Update OC preview version.
sarahelsaig Aug 17, 2024
df63544
Post OC update fixup.
sarahelsaig Aug 17, 2024
8c395bb
Update OC preview version.
sarahelsaig Aug 20, 2024
05acbfa
Update OC preview version.
sarahelsaig Aug 20, 2024
4cde7e2
Update after breaking change.
sarahelsaig Aug 20, 2024
53e4abc
Merge branch 'task/system-text-json-migration' into issue/NEST-536
sarahelsaig Aug 20, 2024
02726cf
Add Google Tag note in the readme.
sarahelsaig Aug 20, 2024
b303f77
Grammar, formatting
Piedone Aug 21, 2024
28e4095
MD formatting
Piedone Aug 21, 2024
3088aef
Update OC preview version.
sarahelsaig Aug 21, 2024
420b05d
Merge remote-tracking branch 'origin/issue/NEST-536' into issue/NEST-536
sarahelsaig Aug 21, 2024
e13a2c2
Simplify condition.
sarahelsaig Aug 21, 2024
a3a68e6
Remove the at="Head" from GoogleTag.
sarahelsaig Aug 21, 2024
47ebf27
Merge remote-tracking branch 'origin/issue/NEST-536' into issue/OSOE-…
sarahelsaig Aug 22, 2024
f8089cd
Update OC preview version.
sarahelsaig Aug 23, 2024
4428861
Post merge fixup.
sarahelsaig Aug 23, 2024
0a2954c
Update OC preview version.
sarahelsaig Aug 23, 2024
7dd6139
Merge remote-tracking branch 'origin/issue/NEST-536' into issue/NEST-536
sarahelsaig Aug 23, 2024
1a056d0
Merge branch 'task/system-text-json-migration' into issue/NEST-536
sarahelsaig Aug 23, 2024
2b186ee
Merge pull request #176 from Lombiq/issue/NEST-536
sarahelsaig Aug 23, 2024
84d13f2
Merge branch 'task/system-text-json-migration' into issue/OSOE-898-new
sarahelsaig Aug 26, 2024
1c5c9f0
Use OC release version.
sarahelsaig Sep 22, 2024
fecaae7
Fix Error CS0738 : it does not have the matching return type of 'Valu…
sarahelsaig Sep 22, 2024
dca7672
Merge pull request #177 from Lombiq/issue/OSOE-898-new
barthamark Sep 23, 2024
713175c
Update HL preview.
sarahelsaig Sep 23, 2024
73cb5be
Update HL.
sarahelsaig Sep 23, 2024
8aa9da3
Merge branch 'task/system-text-json-migration' into issue/OSOE-818
sarahelsaig Sep 24, 2024
3e22cd4
Use AddNavigationProvider everywhere.
sarahelsaig Sep 24, 2024
693f444
Make migrations and background tasks sealed.
sarahelsaig Sep 24, 2024
b9967ae
Seal INavigationProvider, IAsyncResultFilter, IPermissionProvider, St…
sarahelsaig Sep 24, 2024
794ceb1
Remove unnecessary feature attribute.
sarahelsaig Sep 24, 2024
353b8b1
Unusing
sarahelsaig Sep 24, 2024
572b61c
Merge remote-tracking branch 'origin/dev' into issue/OSOE-818
sarahelsaig Sep 24, 2024
02a7f78
Merge remote-tracking branch 'origin/dev' into issue/OSOE-818
sarahelsaig Sep 24, 2024
c576bbb
Merge remote-tracking branch 'origin/dev' into issue/OSOE-818
Piedone Sep 24, 2024
9809cfa
Merge branch 'issue/OSOE-818' of https://github.com/Lombiq/Helpful-Ex…
sarahelsaig Sep 24, 2024
4d60b7f
Update HL NuGet version.
sarahelsaig Sep 25, 2024
e3a0c10
Update UITT version.
sarahelsaig Sep 25, 2024
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
Piedone marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
using System;
using Shouldly;
using System.Diagnostics.CodeAnalysis;

namespace Lombiq.HelpfulExtensions.Tests.UI.Constants;

internal static class GeneratedMigrationCodes
{
// Environment.NewLine is used for this to work regardless of the mismatch of line ending style between the code
// file, the platform where it was compiled, and where it was executed.
public static string Page =
string.Join(
Environment.NewLine,
"_contentDefinitionManager.AlterTypeDefinition(\"Page\", type => type",
" .DisplayedAs(\"Page\")",
" .Creatable()",
" .Listable()",
" .Draftable()",
" .Versionable()",
" .Securable()",
" .WithPart(\"TitlePart\", part => part",
" .WithPosition(\"0\")",
" )",
" .WithPart(\"AutoroutePart\", part => part",
" .WithPosition(\"1\")",
" .WithSettings(new AutoroutePartSettings",
" {",
" AllowCustomPath = true,",
" ShowHomepageOption = true,",
" Pattern = \"{{ Model.ContentItem | display_text | slugify }}\",",
" })",
" )",
" .WithPart(\"FlowPart\", part => part",
" .WithPosition(\"2\")",
" )",
" .WithPart(\"Page\", part => part",
" .WithPosition(\"3\")",
" )",
");",
string.Empty);
[SuppressMessage(
"Usage",
"MA0136:Raw String contains an implicit end of line character",
Justification = "It's wrapped to prevent issues related to that.")]
private const string Page =
"""
_contentDefinitionManager.AlterTypeDefinition("Page", type => type
.DisplayedAs("Page")
.Creatable()
.Listable()
.Draftable()
.Versionable()
.Securable()
.WithPart("TitlePart", part => part
.WithPosition("0")
)
.WithPart("AutoroutePart", part => part
.WithPosition("1")
.WithSettings(new AutoroutePartSettings
{
AllowCustomPath = true,
Pattern = {{ Model.ContentItem | display_text | slugify }},
ShowHomepageOption = true,
AllowUpdatePath = false,
AllowDisabled = false,
AllowRouteContainedItems = false,
ManageContainedItemRoutes = false,
AllowAbsolutePath = false,
})
)
.WithPart("FlowPart", part => part
.WithPosition("2")
)
.WithPart("Page", part => part
.WithPosition("3")
)
);
""";

public static void ShouldBePage(string actual) => actual.ShouldBeByLine(Page);
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ await context.RetryIfStaleOrFailAsync(async () =>
{
await context.ClickReliablyOnAsync(By.ClassName("toggle-showing-generated-migration-code"));

context.Get(By.Id("generated-migration-code").OfAnyVisibility()).GetValue().ShouldBe(GeneratedMigrationCodes.Page);
GeneratedMigrationCodes.ShouldBePage(
context.Get(By.Id("generated-migration-code").OfAnyVisibility()).GetValue());

// Making sure that the collapsible area is open.
context.Get(By.CssSelector("#generated-migration-code-container.collapse.show"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.Tests.UI" Version="10.0.1" />
<PackageReference Include="Lombiq.Tests.UI" Version="10.0.2-alpha.5.osoe-818" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
using Microsoft.Extensions.Localization;
using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.ContentTypes.Editors;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.Json.Nodes;

namespace Lombiq.HelpfulExtensions.Extensions.CodeGeneration;

public class CodeGenerationDisplayDriver : ContentTypeDefinitionDisplayDriver
{
private const int IndentationDepth = 4;
private const string EmptyString = "\"\"";

private readonly IStringLocalizer T;

public CodeGenerationDisplayDriver(IStringLocalizer<CodeGenerationDisplayDriver> stringLocalizer) =>
T = stringLocalizer;

public override IDisplayResult Edit(ContentTypeDefinition model) =>
public override IDisplayResult Edit(ContentTypeDefinition model, BuildEditorContext context) =>
Initialize<ContentTypeMigrationsViewModel>(
"ContentTypeMigrations_Edit",
viewModel => viewModel.MigrationCodeLazy = new Lazy<string>(() =>
Expand All @@ -37,7 +41,7 @@ public override IDisplayResult Edit(ContentTypeDefinition model) =>
codeBuilder.AppendLine(CultureInfo.InvariantCulture, $" .DisplayedAs(\"{model.DisplayName}\")");

GenerateCodeForSettings(codeBuilder, model.GetSettings<ContentTypeSettings>());
AddSettingsWithout<ContentTypeSettings>(codeBuilder, model.Settings, 4);
AddSettingsWithout<ContentTypeSettings>(codeBuilder, model.Settings);
GenerateCodeForParts(codeBuilder, model.Parts);
codeBuilder.AppendLine(");");

Expand All @@ -63,7 +67,7 @@ private void GenerateCodeForParts(StringBuilder codeBuilder, IEnumerable<Content
AddWithLine(codeBuilder, nameof(partSettings.DisplayMode), partSettings.DisplayMode);
AddWithLine(codeBuilder, nameof(partSettings.Editor), partSettings.Editor);

AddSettingsWithout<ContentTypePartSettings>(codeBuilder, part.Settings, 8);
AddSettingsWithout<ContentTypePartSettings>(codeBuilder, part.Settings, 2 * IndentationDepth);

// Checking if anything was added to the part's settings.
if (codeBuilder.Length == partStartingLength)
Expand Down Expand Up @@ -102,7 +106,7 @@ private void GenerateCodeForPartsWithFields(
AddWithLine(codeBuilder, nameof(partSettings.Description), partSettings.Description);
AddWithLine(codeBuilder, nameof(partSettings.DefaultPosition), partSettings.DefaultPosition);

AddSettingsWithout<ContentPartSettings>(codeBuilder, part.Settings, 4);
AddSettingsWithout<ContentPartSettings>(codeBuilder, part.Settings);

foreach (var field in part.Fields)
{
Expand All @@ -116,7 +120,7 @@ private void GenerateCodeForPartsWithFields(
AddWithLine(codeBuilder, nameof(fieldSettings.DisplayMode), fieldSettings.DisplayMode);
AddWithLine(codeBuilder, nameof(fieldSettings.Position), fieldSettings.Position);

AddSettingsWithout<ContentPartFieldSettings>(codeBuilder, field.Settings, 8);
AddSettingsWithout<ContentPartFieldSettings>(codeBuilder, field.Settings, 2 * IndentationDepth);

codeBuilder.AppendLine(" )");
}
Expand All @@ -125,32 +129,20 @@ private void GenerateCodeForPartsWithFields(
}
}

private string ConvertJToken(JToken jToken, int indentationDepth)
{
switch (jToken)
private string ConvertNode(JsonNode node, int indentationDepth) =>
node switch
{
case JValue jValue:
var value = jValue.Value;
return value switch
{
bool boolValue => boolValue ? "true" : "false",
string => $"\"{value}\"",
_ => value?.ToString()?.Replace(',', '.'), // Replace decimal commas.
};
case JArray jArray:
return ConvertJArray(jArray, indentationDepth);
case JObject jObject:
return ConvertJObject(jObject, indentationDepth);
default:
throw new NotSupportedException($"Settings values of type {jToken.GetType()} are not supported.");
}
}
JsonValue jsonValue => jsonValue.ToString(),
JsonArray jsonArray => ConvertJsonArray(jsonArray, indentationDepth),
JsonObject jsonObject => ConvertJsonObject(jsonObject, indentationDepth),
_ => throw new NotSupportedException($"Settings values of type {node.GetType()} are not supported."),
};

private string ConvertJArray(JArray jArray, int indentationDepth)
private string ConvertJsonArray(JsonArray jArray, int indentationDepth)
{
var indentation = new string(' ', indentationDepth + 4);
var indentation = new string(' ', indentationDepth + IndentationDepth);

var items = jArray.Select(item => ConvertJToken(item, indentationDepth + 8)).ToList();
var items = jArray.Select(item => ConvertNode(item, indentationDepth + (2 * IndentationDepth))).ToList();

// If the items are formatted (for ListValueOption) then don't inject line-by-line formatting.
if (items.Exists(item => item.ContainsOrdinalIgnoreCase(Environment.NewLine)))
Expand All @@ -164,7 +156,7 @@ private string ConvertJArray(JArray jArray, int indentationDepth)
stringArrayCodeBuilder.AppendLine();
stringArrayCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{indentation}{{");

var itemIndentation = new string(' ', indentationDepth + 8);
var itemIndentation = new string(' ', indentationDepth + (2 * IndentationDepth));

foreach (var item in items)
{
Expand All @@ -176,53 +168,46 @@ private string ConvertJArray(JArray jArray, int indentationDepth)
return stringArrayCodeBuilder.ToString();
}

private string ConvertJObject(JObject jObject, int indentationDepth)
private string ConvertJsonObject(JsonObject jsonObject, int indentationDepth)
{
var braceIndentation = new string(' ', indentationDepth);
var propertyIndentation = new string(' ', indentationDepth + 4);
if (jObject["name"] != null && jObject["value"] != null)
var propertyIndentation = new string(' ', indentationDepth + IndentationDepth);
if (jsonObject["name"] is { } name && jsonObject["value"] is { } value)
{
var objectCodeBuilder = new StringBuilder();
objectCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{braceIndentation}new ListValueOption");
objectCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{braceIndentation}{{");
objectCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{propertyIndentation}Name = \"{jObject["name"]}\",");
objectCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{propertyIndentation}Value = \"{jObject["value"]}\",");
objectCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{propertyIndentation}Name = \"{name}\",");
objectCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{propertyIndentation}Value = \"{value}\",");
objectCodeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{braceIndentation}}},");

return objectCodeBuilder.ToString();
}

// Using a quoted string so it doesn't mess up the syntax highlighting of the rest of the code.
return T["\"FIX ME! Couldn't determine the actual type to instantiate.\" {0}", jObject.ToString()];
return T["\"FIX ME! Couldn't determine the actual type to instantiate.\" {0}", jsonObject.ToString()];
}

private void AddSettingsWithout<T>(StringBuilder codeBuilder, JObject settings, int indentationDepth)
private void AddSettingsWithout<T>(StringBuilder codeBuilder, JsonObject settings, int indentationDepth = IndentationDepth)
{
var indentation = new string(' ', indentationDepth);

var filteredSettings = ((IEnumerable<KeyValuePair<string, JToken>>)settings)
.Where(setting => setting.Key != typeof(T).Name);
var filteredSettings = settings
.Where(pair => pair.Key != typeof(T).Name && pair.Value is JsonObject)
.Select(pair => (pair.Key, (JsonObject)pair.Value));

foreach (var setting in filteredSettings)
foreach (var (typeName, properties) in filteredSettings)
{
var properties = setting.Value.Where(property => property is JProperty).Cast<JProperty>().ToArray();
if (properties.Count == 0) continue;

if (properties.Length == 0) continue;

codeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{indentation}.WithSettings(new {setting.Key}");
codeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{indentation}.WithSettings(new {typeName}");
codeBuilder.AppendLine(indentation + "{");

// This doesn't support multi-level object hierarchies for settings but come on, who uses complex settings
// objects?
for (int i = 0; i < properties.Length; i++)
foreach (var (name, value) in properties)
{
var property = properties[i];

var propertyValue = ConvertJToken(property.Value, indentationDepth);

propertyValue ??= "\"\"";

codeBuilder.AppendLine(CultureInfo.InvariantCulture, $"{indentation} {property.Name} = {propertyValue},");
codeBuilder.AppendLine(
CultureInfo.InvariantCulture,
$"{indentation} {name} = {ConvertNode(value, indentationDepth) ?? EmptyString},");
}

codeBuilder.AppendLine(indentation + "})");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.Extensions.Localization;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Display.Models;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Entities;
using System.Collections.Generic;
Expand Down Expand Up @@ -64,23 +64,17 @@ public override IDisplayResult Edit(ContentSetPart part, BuildPartEditorContext
context.IsNew))
.Location($"Parts:0%{context.TypePartDefinition.Name};0");

public override async Task<IDisplayResult> UpdateAsync(
ContentSetPart part,
IUpdateModel updater,
UpdatePartEditorContext context)
public override async Task<IDisplayResult> UpdateAsync(ContentSetPart part, UpdatePartEditorContext context)
{
var viewModel = new ContentSetPartViewModel();
var viewModel = await context.CreateModelAsync<ContentSetPartViewModel>(Prefix);

if (await updater.TryUpdateModelAsync(viewModel, Prefix))
{
part.Key = viewModel.Key;
part.Key = viewModel.Key;

// Need to do this here to support displaying the message to save before adding when the
// item has not been saved yet.
if (string.IsNullOrEmpty(part.ContentSet))
{
part.ContentSet = _idGenerator.GenerateUniqueId();
}
// Need to do this here to support displaying the message to save before adding when the item has not been saved
// yet.
if (string.IsNullOrEmpty(part.ContentSet))
{
part.ContentSet = _idGenerator.GenerateUniqueId();
}

return await EditAsync(part, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OrchardCore.ContentManagement.Metadata.Settings;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading.Tasks;

namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels;
Expand All @@ -33,8 +34,7 @@ public class ContentSetPartViewModel
public string DisplayName =>
Definition?
.Settings?
.Property(nameof(ContentTypePartSettings))?
.Value
.GetMaybe(nameof(ContentTypePartSettings))?
.ToObject<ContentTypePartSettings>()?
.DisplayName ?? Definition?.Name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Activities;
using Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Models;
using Lombiq.HelpfulLibraries.OrchardCore.Workflow;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.Workflows.Models;
using OrchardCore.Workflows.Services;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;

namespace Lombiq.HelpfulExtensions.Extensions.ContentSets.Workflows.Handlers;
Expand Down Expand Up @@ -54,14 +54,16 @@ public async Task<IEnumerable<ContentSetLinkViewModel>> GetSupportedOptionsAsync
case ContentSetLinkViewModel viewModel:
links.Add(viewModel);
break;
case IEnumerable<object> collection when collection.CastWhere<ExpandoObject>() is { } objects && objects.Any():
links.AddRange(JToken.FromObject(objects).ToObject<IEnumerable<ContentSetLinkViewModel>>());
break;
case ExpandoObject expandoObject:
links.Add(JToken.FromObject(expandoObject).ToObject<ContentSetLinkViewModel>());
links.Add(SerializeAndDeserialize<ContentSetLinkViewModel>(expandoObject));
break;
case IEnumerable<object> collection when
collection.CastWhere<ExpandoObject>().ToList() is { } objects &&
objects.Count != 0:
links.AddRange(SerializeAndDeserialize<IEnumerable<ContentSetLinkViewModel>>(objects));
break;
case string json when !string.IsNullOrWhiteSpace(json):
links.AddRange(JsonConvert.DeserializeObject<List<ContentSetLinkViewModel>>(json));
links.AddRange(JsonSerializer.Deserialize<List<ContentSetLinkViewModel>>(json));
break;
default: continue;
}
Expand All @@ -79,4 +81,7 @@ public Task CreatingAsync(
new CreatingContext(content, definition, contentSet, newKey),
$"{nameof(WorkflowContentSetEventHandler)}.{nameof(CreatingAsync)}" +
$"({content.ContentItemId}, {definition.Name}, {contentSet}, {newKey})");

private static T SerializeAndDeserialize<T>(object source) =>
JNode.FromObject(source).ToObject<T>();
}
Loading