From 1aec856831a80a2d546b2898094c68af028e3edf Mon Sep 17 00:00:00 2001 From: Benedek Farkas Date: Sun, 8 Dec 2024 19:37:09 +0100 Subject: [PATCH] Code and comment styling in MainMenuService and LinkFieldDriver --- .../Navigation/Services/MainMenuService.cs | 10 ++--- .../Orchard.Fields/Drivers/LinkFieldDriver.cs | 43 ++++++++++--------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/Orchard.Web/Core/Navigation/Services/MainMenuService.cs b/src/Orchard.Web/Core/Navigation/Services/MainMenuService.cs index 682df695d..24fe9f8d5 100644 --- a/src/Orchard.Web/Core/Navigation/Services/MainMenuService.cs +++ b/src/Orchard.Web/Core/Navigation/Services/MainMenuService.cs @@ -25,7 +25,7 @@ namespace Orchard.Core.Navigation.Services { } public IContent GetMenu(string menuName) { - if(string.IsNullOrWhiteSpace(menuName)) { + if (string.IsNullOrWhiteSpace(menuName)) { return null; } @@ -37,7 +37,7 @@ namespace Orchard.Core.Navigation.Services { } public IContent GetMenu(int menuId) { - return _contentManager.Get(menuId, VersionOptions.Published); + return _contentManager.Get(menuId, VersionOptions.Published); } public MenuPart Get(int menuPartId) { @@ -45,11 +45,11 @@ namespace Orchard.Core.Navigation.Services { } public IContent Create(string name) { - - if(string.IsNullOrWhiteSpace(name)) { + + if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(name); } - + var menu = _contentManager.Create("Menu"); menu.As().Title = name; diff --git a/src/Orchard.Web/Modules/Orchard.Fields/Drivers/LinkFieldDriver.cs b/src/Orchard.Web/Modules/Orchard.Fields/Drivers/LinkFieldDriver.cs index 7f619fb92..73737fe91 100644 --- a/src/Orchard.Web/Modules/Orchard.Fields/Drivers/LinkFieldDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Fields/Drivers/LinkFieldDriver.cs @@ -1,12 +1,10 @@ -using Orchard.ContentManagement; +using System; +using Orchard.ContentManagement; using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Handlers; using Orchard.Fields.Fields; using Orchard.Fields.Settings; using Orchard.Localization; -using System; -using System.Collections.Generic; -using System.Security.Policy; namespace Orchard.Fields.Drivers { public class LinkFieldDriver : ContentFieldDriver { @@ -60,28 +58,33 @@ namespace Orchard.Fields.Drivers { } else if (settings.LinkTextMode == LinkTextMode.Required && String.IsNullOrWhiteSpace(field.Text)) { updater.AddModelError(GetPrefix(field, part), T("Text is required for {0}.", T(field.DisplayName))); - } else if (!String.IsNullOrWhiteSpace(field.Value)) { - // Check if it's a valid uri, considering that there may be the link to an anchor only - // e.g.: field.Value = "#divId" - // Take everything before the first "#" character and check if it's a valid uri. - // If there is no character before the first "#", consider the value as a valid one (because it is a reference to a div inside the same page) + } + else if (!String.IsNullOrWhiteSpace(field.Value)) { + // Check if it's a valid URI, considering that there may be the link to an anchor only, e.g., + // field.Value = "#divId". + // Take everything before the first "#" character and check if it's a valid URI. If there is no + // character before the first "#", consider the value as a valid one (because it is a reference to + // a div inside the same page). if (field.Value.StartsWith("#")) { - // The field value is a tag id reference - // For html 5, a tag id is valid as long as it doesn't contain white spaces + // The field value is a tag id reference. + // For HTML 5, a tag id is valid as long as it doesn't contain white spaces. if (field.Value.IndexOf(' ') >= 0) { - updater.AddModelError(GetPrefix(field, part), T("{0} is an invalid url.", field.Value)); + updater.AddModelError(GetPrefix(field, part), T("{0} is an invalid URL.", field.Value)); } - } else { + } + else { var urlAndRef = field.Value.Split(new char[] { '#' }, 2); - // Since field value is a proper url and not a tag id only, assume the first part of the array is the actual url to link to + // Since field value is a proper URL and not a tag id only, assume the first part of the array + // is the actual URL to link to. if (!String.IsNullOrWhiteSpace(urlAndRef[0]) && !Uri.IsWellFormedUriString(urlAndRef[0], UriKind.RelativeOrAbsolute)) { - updater.AddModelError(GetPrefix(field, part), T("{0} is an invalid url.", field.Value)); - } else if (urlAndRef.Length > 1) { - // The second part of the url is the id reference - // For html 5, a tag id is valid as long as it doesn't contain white spaces + updater.AddModelError(GetPrefix(field, part), T("{0} is an invalid URL.", field.Value)); + } + else if (urlAndRef.Length > 1) { + // The second part of the URL is the id reference. + // For HTML 5, a tag id is valid as long as it doesn't contain white spaces. if (urlAndRef[1].IndexOf(' ') >= 0) { - updater.AddModelError(GetPrefix(field, part), T("{0} is an invalid url.", field.Value)); + updater.AddModelError(GetPrefix(field, part), T("{0} is an invalid URL.", field.Value)); } } } @@ -112,7 +115,7 @@ namespace Orchard.Fields.Drivers { protected override void Describe(DescribeMembersContext context) { context .Member("Text", typeof(string), T("Text"), T("The text of the link.")) - .Member(null, typeof(string), T("Url"), T("The url of the link.")) + .Member(null, typeof(string), T("Url"), T("The URL of the link.")) .Enumerate(() => field => new[] { field.Value }); } }