Skip to content

Commit

Permalink
Update GetPartWrapperCssClasses and GetFieldWrapperCssClasses helpers (
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Oct 27, 2023
1 parent 0c4e054 commit e800bcb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace OrchardCore;

public static class CssOrchardHelper
public static class CssOrchardHelperExtensions
{
private const string FieldWrapperPrefix = "field-wrapper";
private const string PartWrapperPrefix = "content-part-wrapper";
public static string GetPartWrapperCssClasses(this IOrchardHelper helper, ContentTypePartDefinition partDefinition)

public static string GetPartWrapperCssClasses(this IOrchardHelper helper, ContentTypePartDefinition partDefinition, params string[] additionalClasses)
{
var items = new List<string>()
{
Expand All @@ -19,17 +19,22 @@ public static string GetPartWrapperCssClasses(this IOrchardHelper helper, Conten
if (partDefinition != null)
{
items.Add($"{PartWrapperPrefix}-{partDefinition.PartDefinition.Name.HtmlClassify()}");

if (partDefinition.IsNamedPart())
{
items.Add($"{PartWrapperPrefix}-{partDefinition.Name.HtmlClassify()}");
}
}

if (additionalClasses?.Length > 0)
{
items.AddRange(additionalClasses);
}

return helper.GetWrapperCssClasses(items.ToArray());
}
public static string GetFieldWrapperCssClasses(this IOrchardHelper helper, ContentPartFieldDefinition fieldDefinition)

public static string GetFieldWrapperCssClasses(this IOrchardHelper helper, ContentPartFieldDefinition fieldDefinition, params string[] additionalClasses)
{
var items = new List<string>()
{
Expand All @@ -39,13 +44,18 @@ public static string GetFieldWrapperCssClasses(this IOrchardHelper helper, Conte
if (fieldDefinition != null)
{
items.Add($"{FieldWrapperPrefix}-{fieldDefinition.PartDefinition.Name}-{fieldDefinition.Name}".HtmlClassify());

if (fieldDefinition.IsNamedPart())
{
items.Add($"{FieldWrapperPrefix}-{fieldDefinition.ContentTypePartDefinition.Name}-{fieldDefinition.Name}".HtmlClassify());
}
}

if (additionalClasses?.Length > 0)
{
items.AddRange(additionalClasses);
}

return helper.GetWrapperCssClasses(items.ToArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace OrchardCore;

public static class CssOrchardHelper
public static class CssOrchardHelperExtensions
{
public static string GetLimitedWidthWrapperCssClasses(this IOrchardHelper helper, params string[] additionalClasses)
{
Expand Down Expand Up @@ -74,7 +74,8 @@ public static string GetOffsetCssClasses(this IOrchardHelper helper, params stri
return string.Join(' ', Combine(options.OffsetClasses, additionalClasses));
}

private static TheAdminThemeOptions GetThemeOptions(IOrchardHelper helper) => helper.HttpContext.RequestServices.GetService<IOptions<TheAdminThemeOptions>>().Value;
private static TheAdminThemeOptions GetThemeOptions(IOrchardHelper helper)
=> helper.HttpContext.RequestServices.GetService<IOptions<TheAdminThemeOptions>>().Value;

private static IEnumerable<string> Combine(string optionClasses, string[] additionalClasses)
{
Expand Down

0 comments on commit e800bcb

Please sign in to comment.