From 49b57fdb9c2133ee8d1cfa19937506153b90c35b Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Mon, 22 Jan 2024 09:43:27 -0800 Subject: [PATCH] Fix SectionDisplayDriver prefix (#15123) --- .../Drivers/AzureAISearchSettingsDisplayDriver.cs | 11 ----------- .../Drivers/ElasticSettingsDisplayDriver.cs | 11 ----------- .../Drivers/LuceneSettingsDisplayDriver.cs | 11 ----------- .../Drivers/SearchSettingsDisplayDriver.cs | 14 ++------------ .../Drivers/SmsSettingsDisplayDriver.cs | 11 ----------- .../Drivers/TwilioSettingsDisplayDriver.cs | 11 ----------- .../Entities/SectionDisplayDriver.cs | 12 ++++++++++++ .../Handlers/DisplayDriver.cs | 9 +++++---- 8 files changed, 19 insertions(+), 71 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.AzureAI/Drivers/AzureAISearchSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Search.AzureAI/Drivers/AzureAISearchSettingsDisplayDriver.cs index d47776b1c81..db223d97686 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.AzureAI/Drivers/AzureAISearchSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.AzureAI/Drivers/AzureAISearchSettingsDisplayDriver.cs @@ -56,7 +56,6 @@ public override IDisplayResult Edit(AzureAISearchSettings settings) .ToList(); }).Location("Content:2#Azure AI Search;5") .RenderWhen(() => _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext.User, AzureAISearchIndexPermissionHelper.ManageAzureAISearchIndexes)) - .Prefix(Prefix) .OnGroup(SearchConstants.SearchSettingsGroupId); public override async Task UpdateAsync(AzureAISearchSettings section, BuildEditorContext context) @@ -106,16 +105,6 @@ public override async Task UpdateAsync(AzureAISearchSettings sec return Edit(section); } - protected override void BuildPrefix(ISite model, string htmlFieldPrefix) - { - Prefix = typeof(AzureAISearchSettings).Name; - - if (!string.IsNullOrEmpty(htmlFieldPrefix)) - { - Prefix = htmlFieldPrefix + "." + Prefix; - } - } - private static bool AreTheSame(string[] a, string[] b) { if (a == null && b == null) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticSettingsDisplayDriver.cs index 1bd65044e39..62fa00fdcd9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Drivers/ElasticSettingsDisplayDriver.cs @@ -63,7 +63,6 @@ public override IDisplayResult Edit(ElasticSettings settings) ]; }).Location("Content:2#Elasticsearch;10") .RenderWhen(() => _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext.User, Permissions.ManageElasticIndexes)) - .Prefix(Prefix) .OnGroup(SearchConstants.SearchSettingsGroupId); public override async Task UpdateAsync(ElasticSettings section, BuildEditorContext context) @@ -116,14 +115,4 @@ public override async Task UpdateAsync(ElasticSettings section, return await EditAsync(section, context); } - - protected override void BuildPrefix(ISite model, string htmlFieldPrefix) - { - Prefix = typeof(ElasticSettings).Name; - - if (!string.IsNullOrEmpty(htmlFieldPrefix)) - { - Prefix = htmlFieldPrefix + "." + Prefix; - } - } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Drivers/LuceneSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Drivers/LuceneSettingsDisplayDriver.cs index dfa9902e907..49dda406d54 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Drivers/LuceneSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Drivers/LuceneSettingsDisplayDriver.cs @@ -40,7 +40,6 @@ public override async Task EditAsync(LuceneSettings settings, Bu model.SearchIndexes = (await _luceneIndexSettingsService.GetSettingsAsync()).Select(x => x.IndexName); model.AllowLuceneQueriesInSearch = settings.AllowLuceneQueriesInSearch; }).Location("Content:2#Lucene;15") - .Prefix(Prefix) .OnGroup(SearchConstants.SearchSettingsGroupId); } @@ -68,15 +67,5 @@ public override async Task UpdateAsync(LuceneSettings section, B return await EditAsync(section, context); } - - protected override void BuildPrefix(ISite model, string htmlFieldPrefix) - { - Prefix = typeof(LuceneSettings).Name; - - if (!string.IsNullOrEmpty(htmlFieldPrefix)) - { - Prefix = htmlFieldPrefix + "." + Prefix; - } - } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search/Drivers/SearchSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Search/Drivers/SearchSettingsDisplayDriver.cs index f9f7482b5fa..392c46f310f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search/Drivers/SearchSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search/Drivers/SearchSettingsDisplayDriver.cs @@ -53,7 +53,8 @@ public override async Task EditAsync(SearchSettings settings, Bu model.Placeholder = settings.Placeholder; model.PageTitle = settings.PageTitle; model.ProviderName = settings.ProviderName; - }).Location("Content:2").OnGroup(SearchConstants.SearchSettingsGroupId); + }).Location("Content:2") + .OnGroup(SearchConstants.SearchSettingsGroupId); } public override async Task UpdateAsync(SearchSettings section, BuildEditorContext context) @@ -81,16 +82,5 @@ public override async Task UpdateAsync(SearchSettings section, B return await EditAsync(section, context); } - - protected override void BuildPrefix(ISite model, string htmlFieldPrefix) - { - Prefix = typeof(SearchSettings).Name; - - if (!string.IsNullOrEmpty(htmlFieldPrefix)) - { - Prefix = htmlFieldPrefix + "." + Prefix; - } - } - } } diff --git a/src/OrchardCore.Modules/OrchardCore.Sms/Drivers/SmsSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Sms/Drivers/SmsSettingsDisplayDriver.cs index 5ccfe17fd05..ae34d3f81ec 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sms/Drivers/SmsSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sms/Drivers/SmsSettingsDisplayDriver.cs @@ -56,7 +56,6 @@ public override IDisplayResult Edit(SmsSettings settings) }).Location("Content:1#Providers") .RenderWhen(() => _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext?.User, SmsPermissions.ManageSmsSettings)) - .Prefix(Prefix) .OnGroup(SmsSettings.GroupId); public override async Task UpdateAsync(SmsSettings settings, BuildEditorContext context) @@ -90,14 +89,4 @@ public override async Task UpdateAsync(SmsSettings settings, Bui return Edit(settings); } - - protected override void BuildPrefix(ISite model, string htmlFieldPrefix) - { - Prefix = typeof(SmsSettings).Name; - - if (!string.IsNullOrEmpty(htmlFieldPrefix)) - { - Prefix = htmlFieldPrefix + "." + Prefix; - } - } } diff --git a/src/OrchardCore.Modules/OrchardCore.Sms/Drivers/TwilioSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Sms/Drivers/TwilioSettingsDisplayDriver.cs index bf710b79d49..ec6c7836d7b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sms/Drivers/TwilioSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sms/Drivers/TwilioSettingsDisplayDriver.cs @@ -66,7 +66,6 @@ public override IDisplayResult Edit(TwilioSettings settings) model.HasAuthToken = !string.IsNullOrEmpty(settings.AuthToken); }).Location("Content:5#Twilio") .RenderWhen(() => _authorizationService.AuthorizeAsync(_httpContextAccessor.HttpContext?.User, SmsPermissions.ManageSmsSettings)) - .Prefix(Prefix) .OnGroup(SmsSettings.GroupId); } @@ -150,14 +149,4 @@ public override async Task UpdateAsync(ISite site, TwilioSetting return Edit(settings); } - - protected override void BuildPrefix(ISite model, string htmlFieldPrefix) - { - Prefix = typeof(TwilioSettings).Name; - - if (!string.IsNullOrEmpty(htmlFieldPrefix)) - { - Prefix = htmlFieldPrefix + "." + Prefix; - } - } } diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Entities/SectionDisplayDriver.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Entities/SectionDisplayDriver.cs index 964a7ee12b3..107cb19d00f 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Entities/SectionDisplayDriver.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Entities/SectionDisplayDriver.cs @@ -126,5 +126,17 @@ private TSection GetSection(TModel model) ? property.ToObject() : new TSection(); } + + protected override void BuildPrefix(TModel model, string htmlFieldPrefix) + { + if (!string.IsNullOrEmpty(htmlFieldPrefix)) + { + Prefix = $"{htmlFieldPrefix}.{typeof(TModel).Name}.{typeof(TSection).Name}"; + } + else + { + Prefix = $"{typeof(TModel).Name}.{typeof(TSection).Name}"; + } + } } } diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriver.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriver.cs index 308474b782d..947291efd71 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriver.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriver.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using OrchardCore.DisplayManagement.ModelBinding; using OrchardCore.DisplayManagement.Views; @@ -115,11 +114,13 @@ public virtual Task UpdateAsync(TModel model, IUpdateModel updat protected virtual void BuildPrefix(TModel model, string htmlFieldPrefix) { - Prefix = typeof(TModel).Name; - if (!string.IsNullOrEmpty(htmlFieldPrefix)) { - Prefix = htmlFieldPrefix + "." + Prefix; + Prefix = $"{htmlFieldPrefix}.{typeof(TModel).Name}"; + } + else + { + Prefix = typeof(TModel).Name; } } }