From a0cbff2868af8506feb2fdbc3e2f690b007ffe90 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 1 Feb 2021 17:53:40 +1100 Subject: [PATCH] linting --- .../Extensions/HtmlHelperRenderExtensions.cs | 172 +++++++----------- 1 file changed, 67 insertions(+), 105 deletions(-) diff --git a/src/Umbraco.Web.Website/Extensions/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web.Website/Extensions/HtmlHelperRenderExtensions.cs index 449797a8a1..48367c8e44 100644 --- a/src/Umbraco.Web.Website/Extensions/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web.Website/Extensions/HtmlHelperRenderExtensions.cs @@ -578,108 +578,82 @@ namespace Umbraco.Extensions /// /// Helper method to create a new form to execute in the Umbraco request pipeline to a surface controller plugin /// - /// - /// - /// The surface controller to route to - /// - /// - /// - public static MvcForm BeginUmbracoForm(this IHtmlHelper html, string action, Type surfaceType, - object additionalRouteVals, - IDictionary htmlAttributes) - { - return html.BeginUmbracoForm(action, surfaceType, additionalRouteVals, htmlAttributes, FormMethod.Post); - } + public static MvcForm BeginUmbracoForm( + this IHtmlHelper html, + string action, + Type surfaceType, + object additionalRouteVals, + IDictionary htmlAttributes) + => html.BeginUmbracoForm(action, surfaceType, additionalRouteVals, htmlAttributes, FormMethod.Post); /// /// Helper method to create a new form to execute in the Umbraco request pipeline to a surface controller plugin /// /// The type - /// - /// - /// - /// - /// - /// - public static MvcForm BeginUmbracoForm(this IHtmlHelper html, string action, - object additionalRouteVals, - IDictionary htmlAttributes, - FormMethod method) - where T : SurfaceController - { - return html.BeginUmbracoForm(action, typeof(T), additionalRouteVals, htmlAttributes, method); - } + public static MvcForm BeginUmbracoForm( + this IHtmlHelper html, + string action, + object additionalRouteVals, + IDictionary htmlAttributes, + FormMethod method) + where T : SurfaceController => html.BeginUmbracoForm(action, typeof(T), additionalRouteVals, htmlAttributes, method); /// /// Helper method to create a new form to execute in the Umbraco request pipeline to a surface controller plugin /// /// The type - /// - /// - /// - /// - /// - public static MvcForm BeginUmbracoForm(this IHtmlHelper html, string action, - object additionalRouteVals, - IDictionary htmlAttributes) - where T : SurfaceController - { - return html.BeginUmbracoForm(action, typeof(T), additionalRouteVals, htmlAttributes); - } + public static MvcForm BeginUmbracoForm( + this IHtmlHelper html, + string action, + object additionalRouteVals, + IDictionary htmlAttributes) + where T : SurfaceController => html.BeginUmbracoForm(action, typeof(T), additionalRouteVals, htmlAttributes); /// /// Helper method to create a new form to execute in the Umbraco request pipeline to a surface controller plugin /// - /// - /// - /// - /// - /// - /// public static MvcForm BeginUmbracoForm(this IHtmlHelper html, string action, string controllerName, string area, FormMethod method) - { - return html.BeginUmbracoForm(action, controllerName, area, null, new Dictionary(), method); - } + => html.BeginUmbracoForm(action, controllerName, area, null, new Dictionary(), method); /// /// Helper method to create a new form to execute in the Umbraco request pipeline to a surface controller plugin /// - /// - /// - /// - /// - /// public static MvcForm BeginUmbracoForm(this IHtmlHelper html, string action, string controllerName, string area) - { - return html.BeginUmbracoForm(action, controllerName, area, null, new Dictionary()); - } + => html.BeginUmbracoForm(action, controllerName, area, null, new Dictionary()); /// /// Helper method to create a new form to execute in the Umbraco request pipeline to a surface controller plugin /// - /// - /// - /// - /// - /// - /// - /// - /// - public static MvcForm BeginUmbracoForm(this IHtmlHelper html, string action, string controllerName, string area, - object additionalRouteVals, - IDictionary htmlAttributes, - FormMethod method) + public static MvcForm BeginUmbracoForm( + this IHtmlHelper html, + string action, + string controllerName, + string area, + object additionalRouteVals, + IDictionary htmlAttributes, + FormMethod method) { if (action == null) + { throw new ArgumentNullException(nameof(action)); - if (string.IsNullOrEmpty(action)) - throw new ArgumentException("Value can't be empty.", nameof(action)); - if (controllerName == null) - throw new ArgumentNullException(nameof(controllerName)); - if (string.IsNullOrWhiteSpace(controllerName)) - throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(controllerName)); + } - var umbracoContextAccessor = GetRequiredService(html); + if (string.IsNullOrEmpty(action)) + { + throw new ArgumentException("Value can't be empty.", nameof(action)); + } + + if (controllerName == null) + { + throw new ArgumentNullException(nameof(controllerName)); + } + + if (string.IsNullOrWhiteSpace(controllerName)) + { + throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(controllerName)); + } + + IUmbracoContextAccessor umbracoContextAccessor = GetRequiredService(html); var formAction = umbracoContextAccessor.UmbracoContext.OriginalRequestUrl.PathAndQuery; return html.RenderForm(formAction, method, htmlAttributes, controllerName, action, area, additionalRouteVals); } @@ -687,45 +661,30 @@ namespace Umbraco.Extensions /// /// Helper method to create a new form to execute in the Umbraco request pipeline to a surface controller plugin /// - /// - /// - /// - /// - /// - /// - /// - public static MvcForm BeginUmbracoForm(this IHtmlHelper html, string action, string controllerName, string area, - object additionalRouteVals, - IDictionary htmlAttributes) - { - return html.BeginUmbracoForm(action, controllerName, area, additionalRouteVals, htmlAttributes, FormMethod.Post); - } + public static MvcForm BeginUmbracoForm( + this IHtmlHelper html, + string action, + string controllerName, + string area, + object additionalRouteVals, + IDictionary htmlAttributes) => html.BeginUmbracoForm(action, controllerName, area, additionalRouteVals, htmlAttributes, FormMethod.Post); /// /// This renders out the form for us /// - /// - /// - /// - /// - /// - /// - /// - /// - /// /// /// This code is pretty much the same as the underlying MVC code that writes out the form /// - private static MvcForm RenderForm(this IHtmlHelper htmlHelper, - string formAction, - FormMethod method, - IDictionary htmlAttributes, - string surfaceController, - string surfaceAction, - string area, - object additionalRouteVals = null) + private static MvcForm RenderForm( + this IHtmlHelper htmlHelper, + string formAction, + FormMethod method, + IDictionary htmlAttributes, + string surfaceController, + string surfaceAction, + string area, + object additionalRouteVals = null) { - // ensure that the multipart/form-data is added to the HTML attributes if (htmlAttributes.ContainsKey("enctype") == false) { @@ -734,8 +693,10 @@ namespace Umbraco.Extensions var tagBuilder = new TagBuilder("form"); tagBuilder.MergeAttributes(htmlAttributes); + // action is implicitly generated, so htmlAttributes take precedence. tagBuilder.MergeAttribute("action", formAction); + // method is an explicit parameter, so it takes precedence over the htmlAttributes. tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true); var traditionalJavascriptEnabled = htmlHelper.ViewContext.ClientValidationEnabled; @@ -748,6 +709,7 @@ namespace Umbraco.Extensions htmlHelper.ViewContext.Writer.Write(tagBuilder.RenderStartTag()); var htmlEncoder = GetRequiredService(htmlHelper); + // new UmbracoForm: var theForm = new UmbracoForm(htmlHelper.ViewContext, htmlEncoder, surfaceController, surfaceAction, area, additionalRouteVals);