diff --git a/src/OrchardCore.Build/Dependencies.AspNetCore.props b/src/OrchardCore.Build/Dependencies.AspNetCore.props index f8555a48223..7ca5cf3a1c9 100644 --- a/src/OrchardCore.Build/Dependencies.AspNetCore.props +++ b/src/OrchardCore.Build/Dependencies.AspNetCore.props @@ -39,7 +39,6 @@ - diff --git a/src/OrchardCore.Build/Dependencies.props b/src/OrchardCore.Build/Dependencies.props index 33ced7a405a..087528a07f3 100644 --- a/src/OrchardCore.Build/Dependencies.props +++ b/src/OrchardCore.Build/Dependencies.props @@ -47,7 +47,6 @@ - @@ -64,11 +63,11 @@ - - - - - + + + + + diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Deployment/AdminMenuDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Deployment/AdminMenuDeploymentSource.cs index c90a7107ccc..27fc5503f44 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Deployment/AdminMenuDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Deployment/AdminMenuDeploymentSource.cs @@ -1,6 +1,5 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using OrchardCore.AdminMenu.Services; using OrchardCore.Deployment; @@ -24,18 +23,16 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var data = new JArray(); - result.Steps.Add(new JObject( - new JProperty("name", "AdminMenu"), - new JProperty("data", data) - )); - - // For each AdminNode, store info about its concrete type: linkAdminNode, contentTypesAdminNode etc... - var serializer = new JsonSerializer() { TypeNameHandling = TypeNameHandling.Auto }; + var data = new JsonArray(); + result.Steps.Add(new JsonObject + { + ["name"] = "AdminMenu", + ["data"] = data, + }); foreach (var adminMenu in (await _adminMenuService.GetAdminMenuListAsync()).AdminMenu) { - var objectData = JObject.FromObject(adminMenu, serializer); + var objectData = JObject.FromObject(adminMenu); data.Add(objectData); } diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs index efc4c7c01f9..26a764f6ba5 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Recipes/AdminMenuStep.cs @@ -1,8 +1,7 @@ using System; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using OrchardCore.AdminMenu.Services; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; @@ -30,11 +29,11 @@ public async Task ExecuteAsync(RecipeExecutionContext context) var model = context.Step.ToObject(); - var serializer = new JsonSerializer() { TypeNameHandling = TypeNameHandling.Auto }; + // var serializer = new JsonSerializer() { TypeNameHandling = TypeNameHandling.Auto }; - foreach (var token in model.Data.Cast()) + foreach (var token in model.Data.Cast()) { - var adminMenu = token.ToObject(serializer); + var adminMenu = token.ToObject(/*serializer*/); // When the id is not supplied generate an id, otherwise replace the menu if it exists, or create a new menu. if (string.IsNullOrEmpty(adminMenu.Id)) @@ -51,6 +50,6 @@ public async Task ExecuteAsync(RecipeExecutionContext context) public class AdminMenuStepModel { - public JArray Data { get; set; } + public JsonArray Data { get; set; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Startup.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Startup.cs index dd486e5157d..ecc71f42c89 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Startup.cs @@ -50,6 +50,9 @@ public override void ConfigureServices(IServiceCollection services) services.AddSingleton(new AdminNodeProviderFactory()); services.AddScoped(); services.AddScoped, LinkAdminNodeDriver>(); + + services.AddAdminNode(); + services.AddAdminNode(); } public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Views/Items/LinkAdminNode.Fields.TreeEdit.cshtml b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Views/Items/LinkAdminNode.Fields.TreeEdit.cshtml index 5e90ec65e66..1b12979744b 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Views/Items/LinkAdminNode.Fields.TreeEdit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Views/Items/LinkAdminNode.Fields.TreeEdit.cshtml @@ -1,6 +1,6 @@ @model LinkAdminNodeViewModel -@using Newtonsoft.Json -@using Newtonsoft.Json.Serialization +@using System.Text.Json +@using System.Text.Json.Nodes @@ -73,8 +73,8 @@
@{ - var selectedItems = JsonConvert.SerializeObject(Model.SelectedItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); - var allItems = JsonConvert.SerializeObject(Model.AllItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + var selectedItems = JConvert.SerializeObject(Model.SelectedItems, JOptions.CamelCase); + var allItems = JConvert.SerializeObject(Model.AllItems, JOptions.CamelCase); } diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Views/Items/PlaceholderAdminNode.Fields.TreeEdit.cshtml b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Views/Items/PlaceholderAdminNode.Fields.TreeEdit.cshtml index a7c70b08cc9..f96e014a3cf 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Views/Items/PlaceholderAdminNode.Fields.TreeEdit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Views/Items/PlaceholderAdminNode.Fields.TreeEdit.cshtml @@ -1,6 +1,6 @@ @model PlaceholderAdminNodeViewModel -@using Newtonsoft.Json -@using Newtonsoft.Json.Serialization +@using System.Text.Json +@using System.Text.Json.Nodes @@ -63,8 +63,8 @@
@{ - var selectedItems = JsonConvert.SerializeObject(Model.SelectedItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); - var allItems = JsonConvert.SerializeObject(Model.AllItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + var selectedItems = JConvert.SerializeObject(Model.SelectedItems, JOptions.CamelCase); + var allItems = JConvert.SerializeObject(Model.AllItems, JOptions.CamelCase); } diff --git a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs index 91e12c5dca2..82805da1f4f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs +++ b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/GraphQLMiddleware.cs @@ -28,9 +28,8 @@ public class GraphQLMiddleware private readonly GraphQLSettings _settings; private readonly IDocumentExecuter _executer; internal static readonly Encoding _utf8Encoding = new UTF8Encoding(false); - private readonly static MediaType _jsonMediaType = new("application/json"); - private readonly static MediaType _graphQlMediaType = new("application/graphql"); - private readonly static JsonSerializerOptions _jsonSerializerOptions = new() { WriteIndented = false, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; + private static readonly MediaType _jsonMediaType = new("application/json"); + private static readonly MediaType _graphQlMediaType = new("application/graphql"); public GraphQLMiddleware( RequestDelegate next, @@ -101,7 +100,7 @@ private async Task ExecuteAsync(HttpContext context, ISchemaFactory schemaServic } else { - request = await JsonSerializer.DeserializeAsync(context.Request.Body, _jsonSerializerOptions); + request = await JsonSerializer.DeserializeAsync(context.Request.Body, JOptions.CamelCase); } } else @@ -189,7 +188,7 @@ private static GraphQLRequest CreateRequestFromQueryString(HttpContext context, if (context.Request.Query.ContainsKey("variables")) { - request.Variables = JsonSerializer.Deserialize(context.Request.Query["variables"], _jsonSerializerOptions); + request.Variables = JConvert.DeserializeObject(context.Request.Query["variables"], JOptions.CamelCase); } if (context.Request.Query.ContainsKey("operationName")) diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs index 18fd0206ab1..833546fdd66 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Handlers/AutoroutePartHandler.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; +using System.Text.Json.Settings; using System.Threading.Tasks; using Fluid; using Fluid.Values; @@ -8,7 +10,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; -using Newtonsoft.Json.Linq; using OrchardCore.Autoroute.Core.Indexes; using OrchardCore.Autoroute.Models; using OrchardCore.Autoroute.ViewModels; @@ -70,7 +71,7 @@ public override async Task PublishedAsync(PublishContentContext context, Autorou { _contentManager ??= _serviceProvider.GetRequiredService(); var containedAspect = await _contentManager.PopulateAspectAsync(context.PublishingItem); - await CheckContainedHomeRouteAsync(part.ContentItem.ContentItemId, containedAspect, context.PublishingItem.Content); + await CheckContainedHomeRouteAsync(part.ContentItem.ContentItemId, containedAspect, (JsonObject)context.PublishingItem.Content); } // Update entries from the index table after the session is committed. @@ -193,13 +194,13 @@ private Task RemoveTagAsync(AutoroutePart part) return _tagCache.RemoveTagAsync($"slug:{part.Path}"); } - private async Task CheckContainedHomeRouteAsync(string containerContentItemId, ContainedContentItemsAspect containedAspect, JObject content) + private async Task CheckContainedHomeRouteAsync(string containerContentItemId, ContainedContentItemsAspect containedAspect, JsonObject content) { foreach (var accessor in containedAspect.Accessors) { var jItems = accessor.Invoke(content); - foreach (var jItem in jItems.Cast()) + foreach (var jItem in jItems.Cast()) { var contentItem = jItem.ToObject(); var handlerAspect = await _contentManager.PopulateAspectAsync(contentItem); @@ -213,7 +214,7 @@ private async Task CheckContainedHomeRouteAsync(string containerContentItemId, C await SetHomeRouteAsync(autoroutePart, homeRoute => { homeRoute[_options.ContentItemIdKey] = containerContentItemId; - homeRoute[_options.JsonPathKey] = jItem.Path; + homeRoute[_options.JsonPathKey] = jItem.GetNormalizedPath(); }); break; @@ -236,18 +237,18 @@ private async Task GenerateContainedPathsFromPatternAsync(ContentItem contentIte // Build the entries for this content item to evaluate for duplicates. var entries = new List(); - await PopulateContainedContentItemRoutesAsync(entries, part.ContentItem.ContentItemId, containedAspect, contentItem.Content, part.Path); + await PopulateContainedContentItemRoutesAsync(entries, part.ContentItem.ContentItemId, containedAspect, (JsonObject)contentItem.Content, part.Path); - await ValidateContainedContentItemRoutesAsync(entries, part.ContentItem.ContentItemId, containedAspect, contentItem.Content, part.Path); + await ValidateContainedContentItemRoutesAsync(entries, part.ContentItem.ContentItemId, containedAspect, (JsonObject)contentItem.Content, part.Path); } - private async Task PopulateContainedContentItemRoutesAsync(List entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JObject content, string basePath) + private async Task PopulateContainedContentItemRoutesAsync(List entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JsonObject content, string basePath) { foreach (var accessor in containedContentItemsAspect.Accessors) { var jItems = accessor.Invoke(content); - foreach (var jItem in jItems.Cast()) + foreach (var jItem in jItems.Cast()) { var contentItem = jItem.ToObject(); var handlerAspect = await _contentManager.PopulateAspectAsync(contentItem); @@ -260,7 +261,7 @@ private async Task PopulateContainedContentItemRoutesAsync(List path = (basePath.EndsWith('/') ? basePath : basePath + '/') + handlerAspect.Path.TrimStart('/'); } - entries.Add(new AutorouteEntry(containerContentItemId, path, contentItem.ContentItemId, jItem.Path) + entries.Add(new AutorouteEntry(containerContentItemId, path, contentItem.ContentItemId, jItem.GetNormalizedPath()) { DocumentId = contentItem.Id }); @@ -273,13 +274,13 @@ private async Task PopulateContainedContentItemRoutesAsync(List } } - private async Task ValidateContainedContentItemRoutesAsync(List entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JObject content, string basePath) + private async Task ValidateContainedContentItemRoutesAsync(List entries, string containerContentItemId, ContainedContentItemsAspect containedContentItemsAspect, JsonObject content, string basePath) { foreach (var accessor in containedContentItemsAspect.Accessors) { var jItems = accessor.Invoke(content); - foreach (var jItem in jItems.Cast()) + foreach (var jItem in jItems.Cast()) { var contentItem = jItem.ToObject(); var containedAutoroutePart = contentItem.As(); @@ -297,7 +298,7 @@ private async Task ValidateContainedContentItemRoutesAsync(List containedAutoroutePart.Apply(); // Merge because we have disconnected the content item from it's json owner. - jItem.Merge(contentItem.Content, new JsonMergeSettings + jItem.Merge((JsonObject)contentItem.Content, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Replace, MergeNullValueHandling = MergeNullValueHandling.Merge @@ -315,7 +316,7 @@ private async Task ValidateContainedContentItemRoutesAsync(List containedAutoroutePart.Apply(); // Merge because we have disconnected the content item from it's json owner. - jItem.Merge(contentItem.Content, new JsonMergeSettings + jItem.Merge((JsonObject)contentItem.Content, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Replace, MergeNullValueHandling = MergeNullValueHandling.Merge diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Extensions/ContentPartFieldDefinitionExtensions.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Extensions/ContentPartFieldDefinitionExtensions.cs index 143688b62ba..cd8c62e25c0 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Extensions/ContentPartFieldDefinitionExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Extensions/ContentPartFieldDefinitionExtensions.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.ContentManagement.Metadata.Models; @@ -13,8 +13,8 @@ public static TField GetContentField( ContentItem contentItem) where TField : ContentField { - if (((JObject)contentItem.Content)[fieldDefinition.PartDefinition.Name] is not JObject jPart || - jPart[fieldDefinition.Name] is not JObject jField) + if (((JsonObject)contentItem.Content)[fieldDefinition.PartDefinition.Name] is not JsonObject jPart || + jPart[fieldDefinition.Name] is not JsonObject jField) { return null; } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/UserNamesExtensions.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/UserNamesExtensions.cs index 1a10037110f..0fd79733ff6 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/UserNamesExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Fields/UserNamesExtensions.cs @@ -1,5 +1,5 @@ using System; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.ContentFields.Fields { @@ -13,9 +13,9 @@ public static class UserNamesExtensions /// public static string[] GetUserNames(this UserPickerField userPickerField) { - var userNames = userPickerField.Content["UserNames"] as JArray; + var userNames = (JsonArray)userPickerField.Content["UserNames"]; - return userNames != null ? userNames.ToObject() : []; + return userNames is not null ? userNames.ToObject() : []; } /// diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ContentFieldsProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ContentFieldsProvider.cs index 410dc161988..6e3238a6e04 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ContentFieldsProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Fields/ContentFieldsProvider.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using GraphQL.Resolvers; using GraphQL.Types; -using Newtonsoft.Json.Linq; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentFields.GraphQL.Types; using OrchardCore.ContentManagement; @@ -22,7 +21,7 @@ public class ContentFieldsProvider : IContentFieldProvider Description = "Boolean field", FieldType = typeof(BooleanGraphType), UnderlyingType = typeof(BooleanField), - FieldAccessor = field => (bool)field.Content.Value + FieldAccessor = field => field.Content.Value, } }, { @@ -32,7 +31,7 @@ public class ContentFieldsProvider : IContentFieldProvider Description = "Date field", FieldType = typeof(DateGraphType), UnderlyingType = typeof(DateField), - FieldAccessor = field => (DateTime?)field.Content.Value + FieldAccessor = field => field.Content.Value, } }, { @@ -42,7 +41,7 @@ public class ContentFieldsProvider : IContentFieldProvider Description = "Date & time field", FieldType = typeof(DateTimeGraphType), UnderlyingType = typeof(DateTimeField), - FieldAccessor = field => (DateTime?)field.Content.Value + FieldAccessor = field => field.Content.Value, } }, { @@ -52,7 +51,7 @@ public class ContentFieldsProvider : IContentFieldProvider Description = "Numeric field", FieldType = typeof(DecimalGraphType), UnderlyingType = typeof(NumericField), - FieldAccessor = field => (decimal?)field.Content.Value + FieldAccessor = field => field.Content.Value, } }, { @@ -62,7 +61,7 @@ public class ContentFieldsProvider : IContentFieldProvider Description = "Text field", FieldType = typeof(StringGraphType), UnderlyingType = typeof(TextField), - FieldAccessor = field => (string)field.Content.Text + FieldAccessor = field => field.Content.Text, } }, { @@ -72,7 +71,7 @@ public class ContentFieldsProvider : IContentFieldProvider Description = "Time field", FieldType = typeof(TimeSpanGraphType), UnderlyingType = typeof(TimeField), - FieldAccessor = field => (TimeSpan?)field.Content.Value + FieldAccessor = field => field.Content.Value, } }, { @@ -82,7 +81,7 @@ public class ContentFieldsProvider : IContentFieldProvider Description = "Multi text field", FieldType = typeof(ListGraphType), UnderlyingType = typeof(MultiTextField), - FieldAccessor = field => ((JArray)field.Content.Values)?.ToObject() + FieldAccessor = field => field.Content.Values, } } }; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/HtmlFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/HtmlFieldQueryObjectType.cs index 53684debeb6..22c1674d6b3 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/HtmlFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/GraphQL/Types/HtmlFieldQueryObjectType.cs @@ -1,13 +1,13 @@ using System.Collections.Generic; using System.Linq; using System.Text.Encodings.Web; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Fluid.Values; using GraphQL; using GraphQL.Types; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Localization; -using Newtonsoft.Json.Linq; using OrchardCore.Apis.GraphQL; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentFields.Settings; @@ -39,9 +39,9 @@ private static async Task RenderHtml(IResolveFieldContext ctx var shortcodeService = serviceProvider.GetRequiredService(); var contentDefinitionManager = serviceProvider.GetRequiredService(); - var jObject = ctx.Source.Content as JObject; + var jObject = (JsonObject)ctx.Source.Content; // The JObject.Path is consistent here even when contained in a bag part. - var jsonPath = jObject.Path; + var jsonPath = jObject.GetNormalizedPath(); var paths = jsonPath.Split('.'); var partName = paths[0]; var fieldName = paths[1]; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/BooleanFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/BooleanFieldSettingsDriver.cs index a575124bb45..9f3759b332d 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/BooleanFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/BooleanFieldSettingsDriver.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; @@ -10,7 +11,14 @@ public class BooleanFieldSettingsDriver : ContentPartFieldDefinitionDisplayDrive { public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { - return Initialize("BooleanFieldSettings_Edit", model => partFieldDefinition.PopulateSettings(model)) + return Initialize("BooleanFieldSettings_Edit", model => + { + var settings = partFieldDefinition.Settings.ToObject(); + + model.Hint = settings.Hint; + model.Label = settings.Label; + model.DefaultValue = settings.DefaultValue; + }) .Location("Content"); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateFieldSettingsDriver.cs index b2597da5692..c332cd76ff6 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateFieldSettingsDriver.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; @@ -10,7 +11,13 @@ public class DateFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver("DateFieldSettings_Edit", model => partFieldDefinition.PopulateSettings(model)) + return Initialize("DateFieldSettings_Edit", model => + { + var settings = partFieldDefinition.Settings.ToObject(); + + model.Hint = settings.Hint; + model.Required = settings.Required; + }) .Location("Content"); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateTimeFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateTimeFieldSettingsDriver.cs index 2a4dbc139c9..4041c83874f 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateTimeFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/DateTimeFieldSettingsDriver.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; @@ -10,7 +11,13 @@ public class DateTimeFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriv { public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { - return Initialize("DateTimeFieldSettings_Edit", model => partFieldDefinition.PopulateSettings(model)) + return Initialize("DateTimeFieldSettings_Edit", model => + { + var settings = partFieldDefinition.Settings.ToObject(); + + model.Hint = settings.Hint; + model.Required = settings.Required; + }) .Location("Content"); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/HtmlFieldMonacoEditorSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/HtmlFieldMonacoEditorSettingsDriver.cs index 56358939740..bcfdbd501f8 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/HtmlFieldMonacoEditorSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/HtmlFieldMonacoEditorSettingsDriver.cs @@ -1,8 +1,7 @@ -using System; +using System.Text.Json; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.Localization; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentFields.ViewModels; using OrchardCore.ContentManagement.Metadata.Models; @@ -28,7 +27,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti var settings = partFieldDefinition.GetSettings(); if (string.IsNullOrWhiteSpace(settings.Options)) { - settings.Options = JsonConvert.SerializeObject(new { automaticLayout = true, language = "html" }, Formatting.Indented); + settings.Options = JConvert.SerializeObject(new { automaticLayout = true, language = "html" }, JOptions.Indented); } model.Options = settings.Options; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LinkFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LinkFieldSettingsDriver.cs index 551bd9370f7..6d61f64e832 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LinkFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LinkFieldSettingsDriver.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; @@ -10,7 +11,19 @@ public class LinkFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver("LinkFieldSettings_Edit", model => partFieldDefinition.PopulateSettings(model)) + return Initialize("LinkFieldSettings_Edit", model => + { + var settings = partFieldDefinition.Settings.ToObject(); + + model.Hint = settings.Hint; + model.HintLinkText = settings.HintLinkText; + model.Required = settings.Required; + model.LinkTextMode = settings.LinkTextMode; + model.UrlPlaceholder = settings.UrlPlaceholder; + model.TextPlaceholder = settings.TextPlaceholder; + model.DefaultUrl = settings.DefaultUrl; + model.DefaultText = settings.DefaultText; + }) .Location("Content"); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LocalizationSetContentPickerFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LocalizationSetContentPickerFieldSettingsDriver.cs index f9383341b7a..fb2a4018eb0 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LocalizationSetContentPickerFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/LocalizationSetContentPickerFieldSettingsDriver.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; @@ -12,8 +13,16 @@ public class LocalizationSetContentPickerFieldSettingsDriver : ContentPartFieldD { public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { - return Initialize("LocalizationSetContentPickerFieldSettings_Edit", model => partFieldDefinition.PopulateSettings(model)) - .Location("Content"); + return Initialize("LocalizationSetContentPickerFieldSettings_Edit", model => + { + var settings = partFieldDefinition.Settings.ToObject(); + + model.Hint = settings.Hint; + model.Required = settings.Required; + model.Multiple = settings.Multiple; + model.DisplayedContentTypes = settings.DisplayedContentTypes; + }) + .Location("Content"); } public override async Task UpdateAsync(ContentPartFieldDefinition partFieldDefinition, UpdatePartFieldEditorContext context) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/MultiTextFieldSettings.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/MultiTextFieldSettings.cs index cf9b5e10e45..8196f7a4b91 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/MultiTextFieldSettings.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/MultiTextFieldSettings.cs @@ -1,5 +1,5 @@ using System; -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace OrchardCore.ContentFields.Settings { @@ -12,13 +12,13 @@ public class MultiTextFieldSettings public class MultiTextFieldValueOption { - [JsonProperty("name")] + [JsonPropertyName("name")] public string Name { get; set; } - [JsonProperty("value")] + [JsonPropertyName("value")] public string Value { get; set; } - [JsonProperty("default")] + [JsonPropertyName("default")] public bool Default { get; set; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/MultiTextFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/MultiTextFieldSettingsDriver.cs index 6c194c294c4..b39c9d07a0b 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/MultiTextFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/MultiTextFieldSettingsDriver.cs @@ -1,6 +1,6 @@ +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Localization; -using Newtonsoft.Json; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentFields.ViewModels; using OrchardCore.ContentManagement.Metadata.Models; @@ -26,7 +26,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti model.Required = settings.Required; model.Hint = settings.Hint; - model.Options = JsonConvert.SerializeObject(settings.Options, Formatting.Indented); + model.Options = JConvert.SerializeObject(settings.Options, JOptions.Indented); }) .Location("Content"); } @@ -42,7 +42,7 @@ public override async Task UpdateAsync(ContentPartFieldDefinitio settings.Hint = model.Hint; try { - settings.Options = JsonConvert.DeserializeObject(model.Options); + settings.Options = JConvert.DeserializeObject(model.Options); } catch { diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/NumericFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/NumericFieldSettingsDriver.cs index db007cb1bd8..ddf2c171f48 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/NumericFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/NumericFieldSettingsDriver.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; @@ -10,7 +11,18 @@ public class NumericFieldSettingsDriver : ContentPartFieldDefinitionDisplayDrive { public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { - return Initialize("NumericFieldSettings_Edit", model => partFieldDefinition.PopulateSettings(model)) + return Initialize("NumericFieldSettings_Edit", model => + { + var settings = partFieldDefinition.Settings.ToObject(); + + model.Hint = settings.Hint; + model.Required = settings.Required; + model.Scale = settings.Scale; + model.Minimum = settings.Minimum; + model.Maximum = settings.Maximum; + model.Placeholder = settings.Placeholder; + model.DefaultValue = settings.DefaultValue; + }) .Location("Content"); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldMonacoEditorSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldMonacoEditorSettingsDriver.cs index 1a41e727359..cd07a5f61ba 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldMonacoEditorSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldMonacoEditorSettingsDriver.cs @@ -1,7 +1,6 @@ -using System; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Localization; -using Newtonsoft.Json; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentFields.ViewModels; using OrchardCore.ContentManagement.Metadata.Models; @@ -27,7 +26,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti var settings = partFieldDefinition.GetSettings(); if (string.IsNullOrWhiteSpace(settings.Options)) { - settings.Options = JsonConvert.SerializeObject(new { automaticLayout = true, language = "html" }, Formatting.Indented); + settings.Options = JConvert.SerializeObject(new { automaticLayout = true, language = "html" }, JOptions.Indented); } model.Options = settings.Options; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldPredefinedListEditorSettings.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldPredefinedListEditorSettings.cs index 4c296500969..4e60c8547c5 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldPredefinedListEditorSettings.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldPredefinedListEditorSettings.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace OrchardCore.ContentFields.Settings { @@ -17,10 +17,10 @@ public enum EditorOption public class ListValueOption { - [JsonProperty("name")] + [JsonPropertyName("name")] public string Name { get; set; } - [JsonProperty("value")] + [JsonPropertyName("value")] public string Value { get; set; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldPredefinedListEditorSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldPredefinedListEditorSettingsDriver.cs index 326a8ed15c5..01329d47d60 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldPredefinedListEditorSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldPredefinedListEditorSettingsDriver.cs @@ -1,7 +1,7 @@ using System; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Localization; -using Newtonsoft.Json; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentFields.ViewModels; using OrchardCore.ContentManagement.Metadata.Models; @@ -27,7 +27,7 @@ public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefiniti model.DefaultValue = settings.DefaultValue; model.Editor = settings.Editor; - model.Options = JsonConvert.SerializeObject(settings.Options ?? [], Formatting.Indented); + model.Options = JConvert.SerializeObject(settings.Options ?? [], JOptions.Indented); }) .Location("Editor"); } @@ -47,7 +47,7 @@ public override async Task UpdateAsync(ContentPartFieldDefinitio settings.Editor = model.Editor; settings.Options = string.IsNullOrWhiteSpace(model.Options) ? [] - : JsonConvert.DeserializeObject(model.Options); + : JConvert.DeserializeObject(model.Options); } catch { diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldSettingsDriver.cs index 78d008477c5..ed5eb8d2c5e 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TextFieldSettingsDriver.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; @@ -10,7 +11,14 @@ public class TextFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver("TextFieldSettings_Edit", model => partFieldDefinition.PopulateSettings(model)) + return Initialize("TextFieldSettings_Edit", model => + { + var settings = partFieldDefinition.Settings.ToObject(); + + model.Hint = settings.Hint; + model.Required = settings.Required; + model.DefaultValue = settings.DefaultValue; + }) .Location("Content"); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TimeFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TimeFieldSettingsDriver.cs index 6eb32bd1d18..dfa539ab27b 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TimeFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/TimeFieldSettingsDriver.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; @@ -10,7 +11,14 @@ public class TimeFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriver("TimeFieldSettings_Edit", model => partFieldDefinition.PopulateSettings(model)) + return Initialize("TimeFieldSettings_Edit", model => + { + var settings = partFieldDefinition.Settings.ToObject(); + + model.Hint = settings.Hint; + model.Required = settings.Required; + model.Step = settings.Step; + }) .Location("Content"); } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/YoutubeFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/YoutubeFieldSettingsDriver.cs index 38b2ca27679..436395fe7e6 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/YoutubeFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Settings/YoutubeFieldSettingsDriver.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement.Metadata.Models; @@ -11,11 +12,13 @@ public class YoutubeFieldSettingsDriver : ContentPartFieldDefinitionDisplayDrive public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { return Initialize("YoutubeFieldSetting_Edit", model => - { - partFieldDefinition.PopulateSettings(model); - model.Height = model.Height != default ? model.Height : 315; - model.Width = model.Width != default ? model.Width : 560; - }).Location("Content"); + { + var settings = partFieldDefinition.Settings.ToObject(); + + model.Height = model.Height != default ? model.Height : 315; + model.Width = model.Width != default ? model.Width : 560; + }) + .Location("Content"); } public async override Task UpdateAsync(ContentPartFieldDefinition partFieldDefinition, UpdatePartFieldEditorContext context) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/ContentPickerField.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/ContentPickerField.Edit.cshtml index 5e68838abd5..6cb05117f7b 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/ContentPickerField.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/ContentPickerField.Edit.cshtml @@ -1,10 +1,10 @@ @model OrchardCore.ContentFields.ViewModels.EditContentPickerFieldViewModel -@using Newtonsoft.Json -@using Newtonsoft.Json.Serialization +@using System.Text.Json +@using System.Text.Json.Nodes @using OrchardCore.Mvc.Utilities @{ var settings = Model.PartFieldDefinition.GetSettings(); - var selectedItems = JsonConvert.SerializeObject(Model.SelectedItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + var selectedItems = JConvert.SerializeObject(Model.SelectedItems, JOptions.CamelCase); var partName = Model.PartFieldDefinition.PartDefinition.Name; var fieldName = Model.PartFieldDefinition.Name; var searchUrl = Url.RouteUrl(new { area = "OrchardCore.ContentFields", controller = "ContentPickerAdmin", action = "SearchContentItems", part = partName, field = fieldName }); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/LocalizationSetContentPickerField.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/LocalizationSetContentPickerField.Edit.cshtml index a583d8d620f..e8cf6d69064 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/LocalizationSetContentPickerField.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/LocalizationSetContentPickerField.Edit.cshtml @@ -1,6 +1,6 @@ @model OrchardCore.ContentFields.ViewModels.EditLocalizationSetContentPickerFieldViewModel -@using Newtonsoft.Json -@using Newtonsoft.Json.Serialization +@using System.Text.Json +@using System.Text.Json.Nodes @using OrchardCore.Environment.Shell @using OrchardCore.Mvc.Utilities @@ -8,7 +8,7 @@ @{ var settings = Model.PartFieldDefinition.GetSettings(); - var selectedItems = JsonConvert.SerializeObject(Model.SelectedItems, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + var selectedItems = JConvert.SerializeObject(Model.SelectedItems, JOptions.CamelCase); var partName = Model.PartFieldDefinition.PartDefinition.Name; var fieldName = Model.PartFieldDefinition.Name; var searchUrl = Url.RouteUrl(new { area = "OrchardCore.ContentFields", controller = "LocalizationSetContentPickerAdmin", action = "SearchLocalizationSets", part = partName, field = fieldName }); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/MultiTextField-Picker.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/MultiTextField-Picker.Edit.cshtml index 19fa9077985..9d8b3572a28 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/MultiTextField-Picker.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/MultiTextField-Picker.Edit.cshtml @@ -1,5 +1,5 @@ @model OrchardCore.ContentFields.ViewModels.EditMultiTextFieldViewModel -@using Newtonsoft.Json +@using System.Text.Json @using OrchardCore.Mvc.Utilities @{ var settings = Model.PartFieldDefinition.GetSettings(); @@ -13,8 +13,8 @@ } } - var jSelectedValues = JsonConvert.SerializeObject(selectedValues); - var jOptions = JsonConvert.SerializeObject(settings.Options.Select(o => new { value = o.Value, name = o.Name })); + var jSelectedValues = JConvert.SerializeObject(selectedValues); + var jOptions = JConvert.SerializeObject(settings.Options.Select(o => new { value = o.Value, name = o.Name })); var partName = Model.PartFieldDefinition.PartDefinition.Name; var fieldName = Model.PartFieldDefinition.Name; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/UserPickerField.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/UserPickerField.Edit.cshtml index 7d65f572c55..ef6c5a48478 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/UserPickerField.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.ContentFields/Views/UserPickerField.Edit.cshtml @@ -1,10 +1,10 @@ @model OrchardCore.ContentFields.ViewModels.EditUserPickerFieldViewModel -@using Newtonsoft.Json -@using Newtonsoft.Json.Serialization +@using System.Text.Json +@using System.Text.Json.Nodes @using OrchardCore.Mvc.Utilities @{ var settings = Model.PartFieldDefinition.GetSettings(); - var selectedUsers = JsonConvert.SerializeObject(Model.SelectedUsers, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); + var selectedUsers = JConvert.SerializeObject(Model.SelectedUsers, JOptions.CamelCase); var partName = Model.PartFieldDefinition.PartDefinition.Name; var fieldName = Model.PartFieldDefinition.Name; var contentTypeName = Model.TypePartDefinition.Name; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ContentDefinitionDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ContentDefinitionDeploymentSource.cs index c28139a959b..2f88284061e 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ContentDefinitionDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ContentDefinitionDeploymentSource.cs @@ -1,6 +1,6 @@ using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.Deployment; @@ -34,11 +34,12 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan : contentTypeDefinitionRecord.ContentPartDefinitionRecords .Where(x => contentDefinitionStep.ContentParts.Contains(x.Name)); - result.Steps.Add(new JObject( - new JProperty("name", "ContentDefinition"), - new JProperty("ContentTypes", JArray.FromObject(contentTypes)), - new JProperty("ContentParts", JArray.FromObject(contentParts)) - )); + result.Steps.Add(new JsonObject + { + ["name"] = "ContentDefinition", + ["ContentTypes"] = JArray.FromObject(contentTypes), + ["ContentParts"] = JArray.FromObject(contentParts), + }); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/DeleteContentDefinitionDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/DeleteContentDefinitionDeploymentSource.cs index 0e07811ebf7..b54de8c1e0c 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/DeleteContentDefinitionDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/DeleteContentDefinitionDeploymentSource.cs @@ -1,5 +1,5 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.Deployment; namespace OrchardCore.ContentTypes.Deployment @@ -13,11 +13,12 @@ public Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult return Task.CompletedTask; } - result.Steps.Add(new JObject( - new JProperty("name", "DeleteContentDefinition"), - new JProperty("ContentTypes", JArray.FromObject(deleteContentDefinitionStep.ContentTypes)), - new JProperty("ContentParts", JArray.FromObject(deleteContentDefinitionStep.ContentParts)) - )); + result.Steps.Add(new JsonObject + { + ["name"] = "DeleteContentDefinition", + ["ContentTypes"] = JArray.FromObject(deleteContentDefinitionStep.ContentTypes), + ["ContentParts"] = JArray.FromObject(deleteContentDefinitionStep.ContentParts), + }); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ReplaceContentDefinitionDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ReplaceContentDefinitionDeploymentSource.cs index cde4d134d66..0b35e8c324d 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ReplaceContentDefinitionDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Deployment/ReplaceContentDefinitionDeploymentSource.cs @@ -1,6 +1,6 @@ using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.Deployment; @@ -34,11 +34,12 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan : contentTypeDefinitionRecord.ContentPartDefinitionRecords .Where(x => replaceContentDefinitionStep.ContentParts.Contains(x.Name)); - result.Steps.Add(new JObject( - new JProperty("name", "ReplaceContentDefinition"), - new JProperty("ContentTypes", JArray.FromObject(contentTypes)), - new JProperty("ContentParts", JArray.FromObject(contentParts)) - )); + result.Steps.Add(new JsonObject + { + ["name"] = "ReplaceContentDefinition", + ["ContentTypes"] = JArray.FromObject(contentTypes), + ["ContentParts"] = JArray.FromObject(contentParts), + }); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs index 50ccef5780c..73caa66a5c5 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ContentDefinitionStep.cs @@ -1,4 +1,5 @@ using System; +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Models; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs index 28206b497e0..2e243eb2e81 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/DeleteContentDefinitionStep.cs @@ -1,4 +1,5 @@ using System; +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.Recipes.Models; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs index 74be3474014..6822f856922 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/RecipeSteps/ReplaceContentDefinitionStep.cs @@ -1,4 +1,5 @@ using System; +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Records; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Recipes/LuceneRecipeEventHandler.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Recipes/LuceneRecipeEventHandler.cs index c188e866936..c412dbf5242 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Recipes/LuceneRecipeEventHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Recipes/LuceneRecipeEventHandler.cs @@ -1,6 +1,6 @@ using System; +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement.Metadata.Records; using OrchardCore.Recipes.Events; using OrchardCore.Recipes.Models; @@ -34,10 +34,10 @@ public Task RecipeStepExecutingAsync(RecipeExecutionContext context) { if (partDefinition.Settings != null) { - if (partDefinition.Settings.TryGetValue("ContentIndexSettings", out var existingPartSettings) && + if (partDefinition.Settings.TryGetPropertyValue("ContentIndexSettings", out var existingPartSettings) && !partDefinition.Settings.ContainsKey("LuceneContentIndexSettings")) { - partDefinition.Settings.Add(new JProperty("LuceneContentIndexSettings", existingPartSettings)); + partDefinition.Settings.Add("LuceneContentIndexSettings", existingPartSettings); } partDefinition.Settings.Remove("ContentIndexSettings"); @@ -49,10 +49,10 @@ public Task RecipeStepExecutingAsync(RecipeExecutionContext context) { if (partDefinition.Settings != null) { - if (partDefinition.Settings.TryGetValue("ContentIndexSettings", out var existingPartSettings) && + if (partDefinition.Settings.TryGetPropertyValue("ContentIndexSettings", out var existingPartSettings) && !partDefinition.Settings.ContainsKey("LuceneContentIndexSettings")) { - partDefinition.Settings.Add(new JProperty("LuceneContentIndexSettings", existingPartSettings)); + partDefinition.Settings.Add("LuceneContentIndexSettings", existingPartSettings); } partDefinition.Settings.Remove("ContentIndexSettings"); @@ -61,10 +61,10 @@ public Task RecipeStepExecutingAsync(RecipeExecutionContext context) { if (fieldDefinition.Settings != null) { - if (fieldDefinition.Settings.TryGetValue("ContentIndexSettings", out var existingFieldSettings) && + if (fieldDefinition.Settings.TryGetPropertyValue("ContentIndexSettings", out var existingFieldSettings) && !fieldDefinition.Settings.ContainsKey("LuceneContentIndexSettings")) { - fieldDefinition.Settings.Add(new JProperty("LuceneContentIndexSettings", existingFieldSettings)); + fieldDefinition.Settings.Add("LuceneContentIndexSettings", existingFieldSettings); } fieldDefinition.Settings.Remove("ContentIndexSettings"); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/ViewModels/EditTypeViewModel.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/ViewModels/EditTypeViewModel.cs index 94d4c6f4497..8097a9367b8 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/ViewModels/EditTypeViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/ViewModels/EditTypeViewModel.cs @@ -1,5 +1,5 @@ +using System.Text.Json.Nodes; using Microsoft.AspNetCore.Mvc.ModelBinding; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement.Metadata.Models; namespace OrchardCore.ContentTypes.ViewModels @@ -25,7 +25,7 @@ public EditTypeViewModel(ContentTypeDefinition contentTypeDefinition) public string[] OrderedPartNames { get; set; } [BindNever] - public JObject Settings { get; set; } + public JsonObject Settings { get; set; } [BindNever] public ContentTypeDefinition TypeDefinition { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AdminNodes/ContentTypesAdminNode.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AdminNodes/ContentTypesAdminNode.cs index dbcf89d26bc..75532047ac5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AdminNodes/ContentTypesAdminNode.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AdminNodes/ContentTypesAdminNode.cs @@ -1,4 +1,3 @@ -using System; using OrchardCore.AdminMenu.Models; namespace OrchardCore.Contents.AdminNodes diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Drivers/AuditTrailContentEventDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Drivers/AuditTrailContentEventDisplayDriver.cs index b9523432fc6..4baba6ce656 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Drivers/AuditTrailContentEventDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Drivers/AuditTrailContentEventDisplayDriver.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.AuditTrail.Drivers; using OrchardCore.AuditTrail.Indexes; using OrchardCore.AuditTrail.Models; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/ApiController.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/ApiController.cs index e33ab9e48e1..8b0826f11c1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/ApiController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Controllers/ApiController.cs @@ -1,11 +1,12 @@ using System.Linq; using System.Net; using System.Security.Claims; +using System.Text.Json.Nodes; +using System.Text.Json.Settings; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Handlers; using OrchardCore.ContentManagement.Metadata; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/ContentItemDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/ContentItemDeploymentSource.cs index d554b5fe710..ab433038e8a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/ContentItemDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AddToDeploymentPlan/ContentItemDeploymentSource.cs @@ -1,6 +1,6 @@ using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.Deployment; @@ -37,18 +37,16 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan var contentStep = result.Steps.FirstOrDefault(s => s["name"]?.ToString() == "Content"); if (contentStep != null) { - var data = contentStep["data"] as JArray; + var data = contentStep["data"] as JsonArray; data.Add(jContentItem); } else { - result.Steps.Add(new JObject( - new JProperty("name", "Content"), - new JProperty("data", new JArray() - { - jContentItem - }) - )); + result.Steps.Add(new JsonObject + { + ["name"] = "Content", + ["data"] = new JsonArray(jContentItem), + }); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AllContentDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AllContentDeploymentSource.cs index 323d8cae69f..25c2c8002c1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AllContentDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/AllContentDeploymentSource.cs @@ -1,5 +1,5 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Records; using OrchardCore.Deployment; @@ -25,11 +25,12 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var data = new JArray(); - result.Steps.Add(new JObject( - new JProperty("name", "Content"), - new JProperty("data", data) - )); + var data = new JsonArray(); + result.Steps.Add(new JsonObject + { + ["name"] = "Content", + ["data"] = data, + }); foreach (var contentItem in await _session.Query(x => x.Published).ListAsync()) { @@ -48,6 +49,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan objectData.Remove(nameof(ContentItem.ModifiedUtc)); objectData.Remove(nameof(ContentItem.PublishedUtc)); } + data.Add(objectData); } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ContentDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ContentDeploymentSource.cs index 2fb8818102d..02cd18cdad5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ContentDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ContentDeploymentSource.cs @@ -1,5 +1,5 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Records; using OrchardCore.Deployment; @@ -28,7 +28,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var data = new JArray(); + var data = new JsonArray(); foreach (var contentItem in await _session.Query(x => x.Published && x.ContentType.IsIn(contentStep.ContentTypes)).ListAsync()) { @@ -47,15 +47,16 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan objectData.Remove(nameof(ContentItem.ModifiedUtc)); objectData.Remove(nameof(ContentItem.PublishedUtc)); } + data.Add(objectData); } - if (data.HasValues) + if (data.HasValues()) { - var jobj = new JObject + var jobj = new JsonObject { ["name"] = "content", - ["data"] = data + ["data"] = data, }; result.Steps.Add(jobj); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/Download/DownloadController.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/Download/DownloadController.cs index 71c1a0721fe..25f29e74092 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/Download/DownloadController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/Download/DownloadController.cs @@ -1,8 +1,8 @@ using System.Text; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json.Linq; using OrchardCore.Admin; using OrchardCore.ContentManagement; using OrchardCore.Modules; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetDeploymentSource.cs index c260524f308..ddc4f0d4748 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetDeploymentSource.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Records; using OrchardCore.Deployment; @@ -37,11 +37,12 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var data = new JArray(); - result.Steps.Add(new JObject( - new JProperty("name", "Content"), - new JProperty("data", data) - )); + var data = new JsonArray(); + result.Steps.Add(new JsonObject + { + ["name"] = "Content", + ["data"] = data, + }); var model = new ExportContentToDeploymentTargetModel(); await _updateModelAccessor.ModelUpdater.TryUpdateModelAsync(model, "ExportContentToDeploymentTarget", m => m.ItemIds, m => m.Latest, m => m.ContentItemId); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/BuildDisplayFilter.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/BuildDisplayFilter.cs index aa3e3347572..2185293499a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/BuildDisplayFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/BuildDisplayFilter.cs @@ -1,8 +1,8 @@ using System; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Fluid; using Fluid.Values; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display; using OrchardCore.DisplayManagement; @@ -41,7 +41,7 @@ static async ValueTask Awaited(Task task, TemplateOptions op { contentItem = null; - if (obj is JObject jObject) + if (obj is JsonObject jObject) { contentItem = jObject.ToObject(); } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/FullTextFilter.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/FullTextFilter.cs index 877dfe62ce9..7a074d36265 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/FullTextFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Liquid/FullTextFilter.cs @@ -1,10 +1,9 @@ -using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Fluid; using Fluid.Values; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Models; using OrchardCore.Liquid; @@ -78,7 +77,7 @@ private static ContentItem GetContentItem(FluidValue input) { contentItem = null; - if (obj is JObject jObject) + if (obj is JsonObject jObject) { contentItem = jObject.ToObject(); // If input is a 'JObject' but which not represents a 'ContentItem', diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs index c1c100ee6bd..f59787d0cd6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Recipes/ContentStep.cs @@ -1,7 +1,7 @@ using System; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.Environment.Shell.Scope; using OrchardCore.Recipes.Models; @@ -45,6 +45,6 @@ public Task ExecuteAsync(RecipeExecutionContext context) public class ContentStepModel { - public JArray Data { get; set; } + public JsonArray Data { get; set; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Scripting/ContentMethodsProvider.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Scripting/ContentMethodsProvider.cs index e837d307de3..90043ffb71b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Scripting/ContentMethodsProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Scripting/ContentMethodsProvider.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Text.Json.Nodes; +using System.Text.Json.Settings; using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.Scripting; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Startup.cs index 95e13f91951..7a188ecfb4a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Startup.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using OrchardCore.Admin; +using OrchardCore.AdminMenu; using OrchardCore.AdminMenu.Services; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display; @@ -217,6 +218,9 @@ static async Task GetContentByHandleAsync(LiquidTemplateContext cont }); services.AddTransient(); + + // Allows to serialize 'AdminNode' derived types. + services.AddAdminNode(); } public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentActivity.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentActivity.cs index 0006ccc3168..ce7900fa5ce 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentActivity.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/ContentActivity.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Nodes; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Localization; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Workflows; using OrchardCore.Workflows.Abstractions.Models; @@ -78,7 +78,7 @@ public override async Task OnWorkflowRestartingAsync(WorkflowExecutionContext wo if (workflowContext.Input.TryGetValue(ContentEventConstants.ContentEventInputKey, out var contentEvent)) { - var contentEventContext = ((JObject)contentEvent).ToObject(); + var contentEventContext = ((JsonObject)contentEvent).ToObject(); if (contentEventContext?.ContentItemVersionId != null) { @@ -92,7 +92,7 @@ public override async Task OnWorkflowRestartingAsync(WorkflowExecutionContext wo if (contentItem == null && workflowContext.Input.TryGetValue(ContentEventConstants.ContentItemInputKey, out var contentItemEvent)) { - var item = ((JObject)contentItemEvent).ToObject(); + var item = ((JsonObject)contentItemEvent).ToObject(); if (item?.ContentItemId != null) { @@ -127,8 +127,8 @@ protected virtual async Task GetContentAsync(WorkflowExecutionContext else { // Try to map the result to a content item. - var json = JsonConvert.SerializeObject(result); - content = JsonConvert.DeserializeObject(json); + var json = JConvert.SerializeObject(result); + content = JConvert.DeserializeObject(json); } } else diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs index c7adb71012b..27c2ede4d60 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/CreateContentTask.cs @@ -1,10 +1,10 @@ using System; using System.Collections.Generic; using System.Text.Encodings.Web; +using System.Text.Json; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.Localization; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Workflows; using OrchardCore.Workflows.Abstractions.Models; @@ -51,7 +51,7 @@ public bool Publish public WorkflowExpression ContentProperties { - get => GetProperty(() => new WorkflowExpression(JsonConvert.SerializeObject(new { DisplayText = S["Enter a title"].Value }, Formatting.Indented))); + get => GetProperty(() => new WorkflowExpression(JConvert.SerializeObject(new { DisplayText = S["Enter a title"].Value }, JOptions.Indented))); set => SetProperty(value); } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs index 1400758cab5..051ee58619b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Activities/UpdateContentTask.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; using System.Text.Encodings.Web; +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Text.Json.Settings; using System.Threading.Tasks; using Microsoft.Extensions.Localization; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Workflows; using OrchardCore.DisplayManagement.ModelBinding; @@ -56,7 +57,11 @@ public WorkflowExpression ContentItemIdExpression public WorkflowExpression ContentProperties { - get => GetProperty(() => new WorkflowExpression(JsonConvert.SerializeObject(new { DisplayText = S["Enter a title"].Value }, Formatting.Indented))); + get => GetProperty(() => + //new WorkflowExpression(JsonConvert.SerializeObject(new { DisplayText = S["Enter a title"].Value }, Formatting.Indented))); + new WorkflowExpression(JConvert.SerializeObject(new { DisplayText = S["Enter a title"].Value }))); + + set => SetProperty(value); } @@ -122,7 +127,7 @@ public async override Task ExecuteAsync(WorkflowExecuti if (!string.IsNullOrWhiteSpace(ContentProperties.Expression)) { var contentProperties = await _expressionEvaluator.EvaluateAsync(ContentProperties, workflowContext, _javaScriptEncoder); - contentItem.Merge(JObject.Parse(contentProperties), new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Replace }); + contentItem.Merge(JsonNode.Parse(contentProperties), new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Replace }); } if (!inlineEventOfSameContentItemId) diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Handlers/ContentItemSerializer.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Handlers/ContentItemSerializer.cs index 0418c94d55c..19088dd534b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Handlers/ContentItemSerializer.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Workflows/Handlers/ContentItemSerializer.cs @@ -1,5 +1,5 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.Workflows.Models; @@ -16,7 +16,7 @@ public ContentItemSerializer(IContentManager contentManager) public async Task DeserializeValueAsync(SerializeWorkflowValueContext context) { - if (context.Input is JObject jObject) + if (context.Input is JsonObject jObject) { var type = jObject.Value("Type"); diff --git a/src/OrchardCore.Modules/OrchardCore.Cors/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Cors/Controllers/AdminController.cs index 5613dabd42c..f4f944535c8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Cors/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Cors/Controllers/AdminController.cs @@ -1,10 +1,10 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Localization; -using Newtonsoft.Json; using OrchardCore.Admin; using OrchardCore.Cors.Services; using OrchardCore.Cors.Settings; @@ -93,7 +93,7 @@ public async Task IndexPOST() var model = new CorsSettingsViewModel(); var configJson = Request.Form["CorsSettings"].First(); - model.Policies = JsonConvert.DeserializeObject(configJson); + model.Policies = JConvert.DeserializeObject(configJson); var corsPolicies = new List(); diff --git a/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs b/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs index 5e106fc28c5..17dc0c6e93e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs @@ -1,5 +1,5 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.Cors.Settings; using OrchardCore.Entities; using OrchardCore.Settings; diff --git a/src/OrchardCore.Modules/OrchardCore.Cors/Views/Admin/Index.cshtml b/src/OrchardCore.Modules/OrchardCore.Cors/Views/Admin/Index.cshtml index 3cfe76ef698..903ffd3a50b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Cors/Views/Admin/Index.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Cors/Views/Admin/Index.cshtml @@ -1,14 +1,9 @@ -@using Newtonsoft.Json @model CorsSettingsViewModel -@{ - var settings = new JsonSerializerSettings { StringEscapeHandling = StringEscapeHandling.EscapeHtml }; -} - diff --git a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/Admin/Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/Admin/Edit.cshtml index 3a9cef34d8a..3e357b8dd8a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/Admin/Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/Admin/Edit.cshtml @@ -10,8 +10,8 @@ .OrderBy(category => category) .ToList(); - var jCategories = JsonConvert.SerializeObject(categories); - var jSelectedCategories = JsonConvert.SerializeObject(Model.Categories); + var jCategories = JConvert.SerializeObject(categories); + var jSelectedCategories = JConvert.SerializeObject(Model.Categories); } diff --git a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/ShortcodeModal.cshtml b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/ShortcodeModal.cshtml index 5fb5eed1194..712a5c16301 100644 --- a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/ShortcodeModal.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/ShortcodeModal.cshtml @@ -16,18 +16,18 @@ and call @await DisplayAsync(await New.ShortcodeModal()) from the fields view .OrderBy(category => category) .ToList(); - var jShortcodes = JsonConvert.SerializeObject(shortcodeDescriptors.Select(d => new { name = d.Name, categories = d.Categories })); - var jCategories = JsonConvert.SerializeObject(categories); + var jShortcodes = JConvert.SerializeObject(shortcodeDescriptors.Select(d => new { name = d.Name, categories = d.Categories })); + var jCategories = JConvert.SerializeObject(categories); - + @* This svg is only used by the trumbowyg editors, but is placed here, once, to reduce complexity The icon for using a .shortcode-modal-input helper is included via javascript when wrapping the .shortcode-modal-input. *@
- + @@ -51,7 +51,7 @@ and call @await DisplayAsync(await New.ShortcodeModal()) from the fields view
- } diff --git a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/_ViewImports.cshtml b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/_ViewImports.cshtml index 4efaff205c4..136e3ff877e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/_ViewImports.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Shortcodes/Views/_ViewImports.cshtml @@ -2,10 +2,10 @@ @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, OrchardCore.DisplayManagement @addTagHelper *, OrchardCore.ResourceManagement +@using System.Text.Json +@using System.Text.Json.Nodes @using Microsoft.Extensions.Localization @using Microsoft.AspNetCore.Mvc.Localization -@using Newtonsoft.Json -@using Newtonsoft.Json.Linq @using OrchardCore.Mvc.Utilities @using OrchardCore.DisplayManagement @using OrchardCore.DisplayManagement.Views diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Deployment/AllSitemapsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Deployment/AllSitemapsDeploymentSource.cs index a58606d9391..8abf5f30e26 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Deployment/AllSitemapsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Deployment/AllSitemapsDeploymentSource.cs @@ -1,6 +1,5 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using OrchardCore.Deployment; using OrchardCore.Sitemaps.Services; @@ -8,11 +7,6 @@ namespace OrchardCore.Sitemaps.Deployment { public class AllSitemapsDeploymentSource : IDeploymentSource { - private static readonly JsonSerializer _serializer = new() - { - TypeNameHandling = TypeNameHandling.Auto, - }; - private readonly ISitemapManager _sitemapManager; public AllSitemapsDeploymentSource(ISitemapManager sitemapManager) @@ -29,12 +23,13 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan var sitemaps = await _sitemapManager.GetSitemapsAsync(); - var jArray = JArray.FromObject(sitemaps, _serializer); + var jArray = JArray.FromObject(sitemaps); - result.Steps.Add(new JObject( - new JProperty("name", "Sitemaps"), - new JProperty("data", jArray) - )); + result.Steps.Add(new JsonObject + { + ["name"] = "Sitemaps", + ["data"] = jArray, + }); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs index 86774f544fa..edfc620e226 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Recipes/SitemapsStep.cs @@ -1,8 +1,7 @@ using System; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; using OrchardCore.Sitemaps.Models; @@ -15,11 +14,6 @@ namespace OrchardCore.Sitemaps.Recipes /// public class SitemapsStep : IRecipeStepHandler { - private static readonly JsonSerializer _serializer = new() - { - TypeNameHandling = TypeNameHandling.Auto - }; - private readonly ISitemapManager _sitemapManager; public SitemapsStep(ISitemapManager sitemapManager) @@ -36,16 +30,16 @@ public async Task ExecuteAsync(RecipeExecutionContext context) var model = context.Step.ToObject(); - foreach (var token in model.Data.Cast()) + foreach (var token in model.Data.Cast()) { - var sitemap = token.ToObject(_serializer); + var sitemap = token.ToObject(); await _sitemapManager.UpdateSitemapAsync(sitemap); } } public class SitemapStepModel { - public JArray Data { get; set; } + public JsonArray Data { get; set; } } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Startup.cs index 5fb0753847e..e61bc838b53 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/Startup.cs @@ -1,4 +1,5 @@ using System; +using System.Text.Json.Serialization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; @@ -91,6 +92,10 @@ public override void ConfigureServices(IServiceCollection services) services.AddScoped>(); services.AddRecipeExecutionStep(); + + // Allows to serialize 'SitemapType' derived types. + services.AddJsonDerivedTypeInfo(); + services.AddJsonDerivedTypeInfo(); } public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) diff --git a/src/OrchardCore.Modules/OrchardCore.Spatial/Drivers/GeoPointFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Spatial/Drivers/GeoPointFieldSettingsDriver.cs index 49f813f1d2b..d33fcdce8c1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Spatial/Drivers/GeoPointFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Spatial/Drivers/GeoPointFieldSettingsDriver.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; @@ -11,7 +12,13 @@ public class GeoPointFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriv { public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { - return Initialize("GeoPointFieldSettings_Edit", model => partFieldDefinition.PopulateSettings(model)) + return Initialize("GeoPointFieldSettings_Edit", model => + { + var settings = partFieldDefinition.Settings.ToObject(); + + model.Hint = settings.Hint; + model.Required = settings.Required; + }) .Location("Content"); } diff --git a/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField-Leaflet.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField-Leaflet.Edit.cshtml index 492ee629e27..78f7e52cd21 100644 --- a/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField-Leaflet.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField-Leaflet.Edit.cshtml @@ -1,6 +1,7 @@ -@using OrchardCore.Spatial.ViewModels -@using OrchardCore.Spatial.Settings @using System.Globalization +@using System.Text.Json.Nodes +@using OrchardCore.Spatial.Settings +@using OrchardCore.Spatial.ViewModels @model EditGeoPointFieldViewModel @{ var settings = Model.PartFieldDefinition.Settings.ToObject(); diff --git a/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField.Edit.cshtml index b254f4e64c0..e28bbe4344d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Spatial/Views/GeoPointField.Edit.cshtml @@ -1,8 +1,9 @@ +@using System.Text.Json.Nodes +@using OrchardCore @using OrchardCore.ContentManagement.Metadata.Models -@using OrchardCore.Spatial.ViewModels -@using OrchardCore.Spatial.Settings @using OrchardCore.Mvc.Utilities -@using OrchardCore +@using OrchardCore.Spatial.Settings +@using OrchardCore.Spatial.ViewModels @model EditGeoPointFieldViewModel @{ var settings = Model.PartFieldDefinition.Settings.ToObject(); diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs index 85302937baa..34234213ea8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/AdminController.cs @@ -1,9 +1,10 @@ using System.Linq; +using System.Text.Json.Nodes; +using System.Text.Json.Settings; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Localization; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display; using OrchardCore.ContentManagement.Metadata; @@ -134,7 +135,7 @@ public async Task CreatePost(string id, string taxonomyContentIte else { // Look for the target taxonomy item in the hierarchy. - var parentTaxonomyItem = FindTaxonomyItem(taxonomy.As().Content, taxonomyItemId); + var parentTaxonomyItem = FindTaxonomyItem((JsonObject)taxonomy.As().Content, taxonomyItemId); // Couldn't find targeted taxonomy item. if (parentTaxonomyItem == null) @@ -142,7 +143,7 @@ public async Task CreatePost(string id, string taxonomyContentIte return NotFound(); } - var taxonomyItems = parentTaxonomyItem?.Terms as JArray; + var taxonomyItems = (JsonArray)parentTaxonomyItem?["Terms"]; if (taxonomyItems == null) { @@ -177,7 +178,7 @@ public async Task Edit(string taxonomyContentItemId, string taxon } // Look for the target taxonomy item in the hierarchy. - JObject taxonomyItem = FindTaxonomyItem(taxonomy.As().Content, taxonomyItemId); + JsonObject taxonomyItem = FindTaxonomyItem((JsonObject)taxonomy.As().Content, taxonomyItemId); // Couldn't find targeted taxonomy item. if (taxonomyItem == null) @@ -230,7 +231,7 @@ public async Task EditPost(string taxonomyContentItemId, string t } // Look for the target taxonomy item in the hierarchy. - JObject taxonomyItem = FindTaxonomyItem(taxonomy.As().Content, taxonomyItemId); + JsonObject taxonomyItem = FindTaxonomyItem((JsonObject)taxonomy.As().Content, taxonomyItemId); // Couldn't find targeted taxonomy item. if (taxonomyItem == null) @@ -258,7 +259,7 @@ public async Task EditPost(string taxonomyContentItemId, string t return View(model); } - taxonomyItem.Merge(contentItem.Content, new JsonMergeSettings + taxonomyItem.Merge((JsonObject)contentItem.Content, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Replace, MergeNullValueHandling = MergeNullValueHandling.Merge @@ -304,7 +305,7 @@ public async Task Delete(string taxonomyContentItemId, string tax } // Look for the target taxonomy item in the hierarchy. - var taxonomyItem = FindTaxonomyItem(taxonomy.As().Content, taxonomyItemId); + var taxonomyItem = FindTaxonomyItem((JsonObject)taxonomy.As().Content, taxonomyItemId); // Couldn't find targeted taxonomy item. if (taxonomyItem == null) @@ -312,7 +313,8 @@ public async Task Delete(string taxonomyContentItemId, string tax return NotFound(); } - taxonomyItem.Remove(); + taxonomy.As().Content.Remove(taxonomyItemId); + await _session.SaveAsync(taxonomy); await _notifier.SuccessAsync(H["Taxonomy item deleted successfully."]); @@ -320,23 +322,20 @@ public async Task Delete(string taxonomyContentItemId, string tax return RedirectToAction(nameof(Edit), "Admin", new { area = "OrchardCore.Contents", contentItemId = taxonomyContentItemId }); } - private JObject FindTaxonomyItem(JObject contentItem, string taxonomyItemId) + private static JsonObject FindTaxonomyItem(JsonObject contentItem, string taxonomyItemId) { if (contentItem["ContentItemId"]?.Value() == taxonomyItemId) { return contentItem; } - if (contentItem.GetValue("Terms") == null) + if (!contentItem.TryGetPropertyValue("Terms", out var terms) || terms is not JsonArray taxonomyItems) { return null; } - var taxonomyItems = (JArray)contentItem["Terms"]; - - JObject result; - - foreach (var taxonomyItem in taxonomyItems.Cast()) + JsonObject result; + foreach (var taxonomyItem in taxonomyItems.Cast()) { // Search in inner taxonomy items. result = FindTaxonomyItem(taxonomyItem, taxonomyItemId); diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/TagController.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/TagController.cs index 8a1cd945e41..a598ea8e370 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/TagController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Controllers/TagController.cs @@ -110,4 +110,3 @@ public async Task CreatePost(string taxonomyContentItemId, string } } } - diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs index 321f14feb79..865ea3d37a4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Cysharp.Text; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.Extensions.Localization; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; using OrchardCore.Contents.ViewModels; @@ -138,7 +138,7 @@ private static void PopulateTermEntries(List termEntries, IEnum { var children = Array.Empty(); - if (contentItem.Content.Terms is JArray termsArray) + if (((JsonObject)contentItem.Content)["Terms"] is JsonArray termsArray) { children = termsArray.ToObject(); } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDisplayDriver.cs index 936d363ae55..0654ec92aa9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDisplayDriver.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDriverHelper.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDriverHelper.cs index 79a4177d726..566be2ef874 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDriverHelper.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldDriverHelper.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; using OrchardCore.ContentManagement; using OrchardCore.Taxonomies.Fields; using OrchardCore.Taxonomies.ViewModels; @@ -20,7 +20,7 @@ public static void PopulateTermEntries(List termEntries, TaxonomyFiel { var children = Array.Empty(); - if (contentItem.Content.Terms is JArray termsArray) + if (((JsonObject)contentItem.Content)["Terms"] is JsonArray termsArray) { children = termsArray.ToObject(); } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldTagsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldTagsDisplayDriver.cs index 690b25b1ee3..cefbac24312 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldTagsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyFieldTagsDisplayDriver.cs @@ -1,11 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.Localization; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display.ContentDisplay; using OrchardCore.ContentManagement.Display.Models; @@ -21,11 +20,6 @@ namespace OrchardCore.Taxonomies.Drivers { public class TaxonomyFieldTagsDisplayDriver : ContentFieldDisplayDriver { - private static readonly JsonSerializerSettings _serializerSettings = new() - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - }; - private readonly IContentManager _contentManager; protected readonly IStringLocalizer S; @@ -68,7 +62,7 @@ public override IDisplayResult Edit(TaxonomyField field, BuildFieldEditorContext IsLeaf = te.IsLeaf }); - model.TagTermEntries = JsonConvert.SerializeObject(tagTermEntries, _serializerSettings); + model.TagTermEntries = JNode.FromObject(tagTermEntries, JOptions.CamelCase).ToJsonString(JOptions.Default); } model.Field = field; @@ -109,7 +103,10 @@ public override async Task UpdateAsync(TaxonomyField field, IUpd foreach (var termContentItemId in field.TermContentItemIds) { - var term = TaxonomyOrchardHelperExtensions.FindTerm(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId); + var term = TaxonomyOrchardHelperExtensions.FindTerm( + (JsonArray)taxonomy.Content["TaxonomyPart"]["Terms"], + termContentItemId); + terms.Add(term); } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs index 2a973df24ae..ad02dc12e23 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyPartDisplayDriver.cs @@ -1,10 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.Localization; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Display.ContentDisplay; using OrchardCore.ContentManagement.Display.Models; @@ -60,13 +59,13 @@ public override async Task UpdateAsync(TaxonomyPart part, IUpdat { var originalTaxonomyItems = part.ContentItem.As(); - var newHierarchy = JArray.Parse(model.Hierarchy); + var newHierarchy = JsonNode.Parse(model.Hierarchy).AsArray(); - var taxonomyItems = new JArray(); + var taxonomyItems = new JsonArray(); foreach (var item in newHierarchy) { - taxonomyItems.Add(ProcessItem(originalTaxonomyItems, item as JObject)); + taxonomyItems.Add(ProcessItem(originalTaxonomyItems, item as JsonObject)); } part.Terms = taxonomyItems.ToObject>(); @@ -81,7 +80,7 @@ public override async Task UpdateAsync(TaxonomyPart part, IUpdat /// /// Clone the content items at the specific index. /// - private static JObject GetTaxonomyItemAt(List taxonomyItems, int[] indexes) + private static JsonObject GetTaxonomyItemAt(List taxonomyItems, int[] indexes) { ContentItem taxonomyItem = null; @@ -90,39 +89,39 @@ private static JObject GetTaxonomyItemAt(List taxonomyItems, int[] { if (taxonomyItems == null || taxonomyItems.Count < index) { - // Trying to acces an unknown index + // Trying to access an unknown index return null; } taxonomyItem = taxonomyItems[index]; - var terms = taxonomyItem.Content.Terms as JArray; + var terms = (JsonArray)taxonomyItem.Content["Terms"]; taxonomyItems = terms?.ToObject>(); } - var newObj = JObject.Parse(JsonConvert.SerializeObject(taxonomyItem)); + var newObj = JObject.FromObject(taxonomyItem); if (newObj["Terms"] != null) { - newObj["Terms"] = new JArray(); + newObj["Terms"] = new JsonArray(); } return newObj; } - private JObject ProcessItem(TaxonomyPart originalItems, JObject item) + private JsonObject ProcessItem(TaxonomyPart originalItems, JsonObject item) { var contentItem = GetTaxonomyItemAt(originalItems.Terms, item["index"].ToString().Split('-').Select(x => Convert.ToInt32(x)).ToArray()); - var children = item["children"] as JArray; + var children = item["children"] as JsonArray; - if (children != null) + if (children is not null) { - var taxonomyItems = new JArray(); + var taxonomyItems = new JsonArray(); for (var i = 0; i < children.Count; i++) { - taxonomyItems.Add(ProcessItem(originalItems, children[i] as JObject)); + taxonomyItems.Add(ProcessItem(originalItems, children[i] as JsonObject)); contentItem["Terms"] = taxonomyItems; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Fields/TagNamesExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Fields/TagNamesExtensions.cs index 01fda5f5182..1d7cad4e3d5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Fields/TagNamesExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Fields/TagNamesExtensions.cs @@ -1,5 +1,5 @@ using System; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; namespace OrchardCore.Taxonomies.Fields { @@ -11,7 +11,7 @@ public static class TagNamesExtensions /// public static string[] GetTagNames(this TaxonomyField taxonomyField) { - var tagNames = taxonomyField.Content["TagNames"] as JArray; + var tagNames = (JsonArray)taxonomyField.Content["TagNames"]; return tagNames != null ? tagNames.ToObject() : []; } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/GraphQL/TaxonomyFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/GraphQL/TaxonomyFieldQueryObjectType.cs index a25d2c08110..8c55b7b8eac 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/GraphQL/TaxonomyFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/GraphQL/TaxonomyFieldQueryObjectType.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; +using System.Text.Json.Nodes; using GraphQL.Types; using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; using OrchardCore.Apis.GraphQL; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.GraphQL.Queries.Types; @@ -52,7 +52,10 @@ public TaxonomyFieldQueryObjectType() foreach (var termContentItemId in ids) { - var term = TaxonomyOrchardHelperExtensions.FindTerm(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId); + var term = TaxonomyOrchardHelperExtensions.FindTerm( + (JsonArray)taxonomy.Content["TaxonomyPart"]["Terms"], + termContentItemId); + terms.Add(term); } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TaxonomyPartHandler.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TaxonomyPartHandler.cs index d720fd0fd02..58fd760402c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TaxonomyPartHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TaxonomyPartHandler.cs @@ -1,5 +1,5 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement.Handlers; using OrchardCore.ContentManagement.Routing; using OrchardCore.Taxonomies.Models; @@ -12,9 +12,9 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context, { return context.ForAsync(aspect => { - aspect.Accessors.Add((jObject) => + aspect.Accessors.Add((jsonObject) => { - return jObject["TaxonomyPart"]["Terms"] as JArray; + return jsonObject["TaxonomyPart"]["Terms"] as JsonArray; }); return Task.CompletedTask; diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TermPartContentHandler.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TermPartContentHandler.cs index 6ed2f368e4a..2fde41a6d46 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TermPartContentHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Handlers/TermPartContentHandler.cs @@ -1,5 +1,5 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement.Handlers; using OrchardCore.ContentManagement.Routing; @@ -12,11 +12,11 @@ public override Task GetContentItemAspectAsync(ContentItemAspectContext context) return context.ForAsync(aspect => { // Check this content item contains Terms. - if (context.ContentItem.Content.Terms is JArray children) + if (((JsonNode)context.ContentItem.Content)["Terms"] is JsonArray) { - aspect.Accessors.Add((jObject) => + aspect.Accessors.Add((jsonObject) => { - return jObject["Terms"] as JArray; + return jsonObject["Terms"] as JsonArray; }); } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Helper/TaxonomyOrchardHelperExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Helper/TaxonomyOrchardHelperExtensions.cs index 7b4906a088e..a533078fa5e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Helper/TaxonomyOrchardHelperExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Helper/TaxonomyOrchardHelperExtensions.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; using OrchardCore; using OrchardCore.ContentManagement; using OrchardCore.Taxonomies.Indexing; @@ -30,7 +30,7 @@ public static async Task GetTaxonomyTermAsync(this IOrchardHelper o return null; } - return FindTerm(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId); + return FindTerm((JsonArray)taxonomy.Content.TaxonomyPart.Terms, termContentItemId); } /// @@ -52,7 +52,7 @@ public static async Task> GetInheritedTermsAsync(this IOrchard var terms = new List(); - FindTermHierarchy(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId, terms); + FindTermHierarchy((JsonArray)taxonomy.Content.TaxonomyPart.Terms, termContentItemId, terms); return terms; } @@ -70,18 +70,18 @@ public static async Task> QueryCategorizedContentItemsA return await contentManager.LoadAsync(contentItems); } - internal static ContentItem FindTerm(JArray termsArray, string termContentItemId) + internal static ContentItem FindTerm(JsonArray termsArray, string termContentItemId) { - foreach (var term in termsArray.Cast()) + foreach (var term in termsArray.Cast()) { - var contentItemId = term.GetValue("ContentItemId").ToString(); + var contentItemId = term["ContentItemId"]?.ToString(); if (contentItemId == termContentItemId) { return term.ToObject(); } - if (term.GetValue("Terms") is JArray children) + if (term["Terms"] is JsonArray children) { var found = FindTerm(children, termContentItemId); @@ -95,11 +95,11 @@ internal static ContentItem FindTerm(JArray termsArray, string termContentItemId return null; } - internal static bool FindTermHierarchy(JArray termsArray, string termContentItemId, List terms) + internal static bool FindTermHierarchy(JsonArray termsArray, string termContentItemId, List terms) { - foreach (var term in termsArray.Cast()) + foreach (var term in termsArray.Cast()) { - var contentItemId = term.GetValue("ContentItemId").ToString(); + var contentItemId = term["ContentItemId"]?.ToString(); if (contentItemId == termContentItemId) { @@ -108,7 +108,7 @@ internal static bool FindTermHierarchy(JArray termsArray, string termContentItem return true; } - if (term.GetValue("Terms") is JArray children) + if (term["Terms"] is JsonArray children) { var found = FindTermHierarchy(children, termContentItemId, terms); diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyFieldIndexHandler.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyFieldIndexHandler.cs index 7ef98590fe5..cb0882fbded 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyFieldIndexHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyFieldIndexHandler.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.Contents.Indexing; using OrchardCore.Indexing; @@ -42,7 +42,7 @@ public override async Task BuildIndexAsync(TaxonomyField field, BuildFieldIndexC var inheritedContentItems = new List(); foreach (var contentItemId in field.TermContentItemIds) { - TaxonomyOrchardHelperExtensions.FindTermHierarchy(taxonomy.Content.TaxonomyPart.Terms as JArray, contentItemId, inheritedContentItems); + TaxonomyOrchardHelperExtensions.FindTermHierarchy((JsonArray)taxonomy.Content.TaxonomyPart.Terms, contentItemId, inheritedContentItems); } foreach (var key in context.Keys) diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs index 82ca28726d2..a0500909d4e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Indexing/TaxonomyIndex.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; using OrchardCore.Data; @@ -80,21 +80,19 @@ public override void Describe(DescribeContext context) // Get all field values foreach (var fieldDefinition in fieldDefinitions) { - var jPart = (JObject)contentItem.Content[fieldDefinition.PartDefinition.Name]; - - if (jPart == null) + var jPart = contentItem.Content[fieldDefinition.PartDefinition.Name]; + if (jPart is null) { continue; } - var jField = jPart[fieldDefinition.Name] as JObject; - - if (jField == null) + var jField = jPart[fieldDefinition.Name]; + if (jField is null) { continue; } - var field = jField.ToObject(); + var field = ((JsonObject)jField).ToObject(); foreach (var termContentItemId in field.TermContentItemIds) { diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/InheritedTermsFilter.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/InheritedTermsFilter.cs index 819494a2dd8..7bb674db146 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/InheritedTermsFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/InheritedTermsFilter.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Fluid; using Fluid.Values; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.Liquid; @@ -36,7 +36,7 @@ public async ValueTask ProcessAsync(FluidValue input, FilterArgument var terms = new List(); - TaxonomyOrchardHelperExtensions.FindTermHierarchy(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId, terms); + TaxonomyOrchardHelperExtensions.FindTermHierarchy((JsonArray)taxonomy.Content.TaxonomyPart.Terms, termContentItemId, terms); return FluidValue.Create(terms, ctx.Options); } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/TaxonomyTermsFilter.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/TaxonomyTermsFilter.cs index 336ee98010c..ad2f392701a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/TaxonomyTermsFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Liquid/TaxonomyTermsFilter.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Fluid; using Fluid.Values; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.Liquid; using OrchardCore.Taxonomies.Fields; @@ -30,12 +30,12 @@ public async ValueTask ProcessAsync(FluidValue input, FilterArgument termContentItemIds = field.TermContentItemIds; } else if (input.Type == FluidValues.Object - && input.ToObjectValue() is JObject jobj + && input.ToObjectValue() is JsonObject jobj && jobj.ContainsKey(nameof(TaxonomyField.TermContentItemIds)) && jobj.ContainsKey(nameof(TaxonomyField.TaxonomyContentItemId))) { taxonomyContentItemId = jobj["TaxonomyContentItemId"].Value(); - termContentItemIds = ((JArray)jobj["TermContentItemIds"]).Values().ToArray(); + termContentItemIds = jobj["TermContentItemIds"].Values().ToArray(); } else if (input.Type == FluidValues.Array) { @@ -58,9 +58,11 @@ public async ValueTask ProcessAsync(FluidValue input, FilterArgument foreach (var termContentItemId in termContentItemIds) { - var term = TaxonomyOrchardHelperExtensions.FindTerm(taxonomy.Content.TaxonomyPart.Terms as JArray, termContentItemId); + var term = TaxonomyOrchardHelperExtensions.FindTerm( + (JsonArray)taxonomy.Content["TaxonomyPart"]["Terms"], + termContentItemId); - if (term != null) + if (term is not null) { terms.Add(term); } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldSettingsDriver.cs index adceb7b6935..e70cc65b180 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldSettingsDriver.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; @@ -10,7 +11,17 @@ public class TaxonomyFieldSettingsDriver : ContentPartFieldDefinitionDisplayDriv { public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { - return Initialize("TaxonomyFieldSettings_Edit", model => partFieldDefinition.PopulateSettings(model)) + return Initialize("TaxonomyFieldSettings_Edit", model => + { + var settings = partFieldDefinition.Settings.ToObject(); + + model.Hint = settings.Hint; + model.Required = settings.Required; + model.TaxonomyContentItemId = settings.TaxonomyContentItemId; + model.Unique = settings.Unique; + model.LeavesOnly = settings.LeavesOnly; + model.Open = settings.Open; + }) .Location("Content"); } diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldTagsEditorSettingsDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldTagsEditorSettingsDriver.cs index bc0cf6298eb..b40c5972991 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldTagsEditorSettingsDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Settings/TaxonomyFieldTagsEditorSettingsDriver.cs @@ -1,3 +1,4 @@ +using System.Text.Json.Nodes; using System.Threading.Tasks; using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.ContentTypes.Editors; @@ -10,8 +11,13 @@ public class TaxonomyFieldTagsEditorSettingsDriver : ContentPartFieldDefinitionD { public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition) { - return Initialize("TaxonomyFieldTagsEditorSettings_Edit", model => partFieldDefinition.PopulateSettings(model)) - .Location("Editor"); + return Initialize("TaxonomyFieldTagsEditorSettings_Edit", model => + { + var settings = partFieldDefinition.Settings.ToObject(); + + model.Open = settings.Open; + }) + .Location("Content"); } public override async Task UpdateAsync(ContentPartFieldDefinition partFieldDefinition, UpdatePartFieldEditorContext context) diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/TermShapes.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/TermShapes.cs index 3e10e1bf576..b26847c5947 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/TermShapes.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/TermShapes.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json.Nodes; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; using OrchardCore.ContentManagement; using OrchardCore.DisplayManagement; using OrchardCore.DisplayManagement.Descriptors; @@ -89,7 +89,7 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder) var termContentItemId = termShape.GetProperty("TermContentItemId"); if (!string.IsNullOrEmpty(termContentItemId)) { - level = FindTerm(taxonomyContentItem.Content.TaxonomyPart.Terms as JArray, termContentItemId, level, out var termContentItem); + level = FindTerm((JsonArray)taxonomyContentItem.Content.TaxonomyPart.Terms, termContentItemId, level, out var termContentItem); if (termContentItem == null) { @@ -133,7 +133,7 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder) foreach (var termContentItem in termItems) { ContentItem[] childTerms = null; - if (termContentItem.Content.Terms is JArray termsArray) + if (((JsonObject)termContentItem.Content)["Terms"] is JsonArray termsArray) { childTerms = termsArray.ToObject(); } @@ -171,7 +171,7 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder) foreach (var termContentItem in termItem.GetProperty("Terms")) { ContentItem[] childTerms = null; - if (termContentItem.Content.Terms is JArray termsArray) + if (((JsonObject)termContentItem.Content)["Terms"] is JsonArray termsArray) { childTerms = termsArray.ToObject(); } @@ -250,19 +250,18 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder) return ValueTask.CompletedTask; } - private static int FindTerm(JArray termsArray, string termContentItemId, int level, out ContentItem contentItem) + private int FindTerm(JsonArray termsArray, string termContentItemId, int level, out ContentItem contentItem) { - foreach (var term in termsArray.Cast()) + foreach (var term in termsArray.Cast()) { - var contentItemId = term.GetValue("ContentItemId").ToString(); - + var contentItemId = term["ContentItemId"]?.ToString(); if (contentItemId == termContentItemId) { contentItem = term.ToObject(); return level; } - if (term.GetValue("Terms") is JArray children) + if (term["Terms"] is JsonArray children) { level += 1; level = FindTerm(children, termContentItemId, level, out var foundContentItem); diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Content.TermAdmin.cshtml b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Content.TermAdmin.cshtml index 50604684206..3f7a4ae7e53 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Content.TermAdmin.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Views/Content.TermAdmin.cshtml @@ -1,11 +1,11 @@ -@using Newtonsoft.Json.Linq +@using System.Text.Json.Nodes @inject OrchardCore.ContentManagement.Display.IContentItemDisplayManager ContentItemDisplayManager @inject OrchardCore.DisplayManagement.ModelBinding.IUpdateModelAccessor ModelUpdaterAccessor @{ ContentItem contentItem = Model.ContentItem; - JArray termsArray = contentItem.Content.Terms; + var termsArray = (JsonArray)contentItem.Content.Terms; var index = 0; } @@ -52,7 +52,7 @@ var updater = ModelUpdaterAccessor.ModelUpdater;