Skip to content

Commit

Permalink
Added support for Grid Editor in an IPublishedElement - resolves #7916
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjf authored and nul800sebastiaan committed Apr 9, 2020
1 parent 0184599 commit fdb3c55
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Umbraco.Web/GridTemplateExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@ public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedContent
return html.Partial(view, model);
}

public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedElement contentItem)
{
return html.GetGridHtml(contentItem, "bodyText", "bootstrap3");
}

public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedElement contentItem, string propertyAlias)
{
if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias));
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyAlias));

return html.GetGridHtml(contentItem, propertyAlias, "bootstrap3");
}

public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedElement contentItem, string propertyAlias, string framework)
{
if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias));
if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(propertyAlias));

var view = "Grid/" + framework;
var prop = contentItem.GetProperty(propertyAlias);
if (prop == null) throw new InvalidOperationException("No property type found with alias " + propertyAlias);
var model = prop.GetValue();

var asString = model as string;
if (asString != null && string.IsNullOrEmpty(asString)) return new MvcHtmlString(string.Empty);

return html.Partial(view, model);
}
public static MvcHtmlString GetGridHtml(this IPublishedProperty property, HtmlHelper html, string framework = "bootstrap3")
{
var asString = property.GetValue() as string;
Expand Down

0 comments on commit fdb3c55

Please sign in to comment.