Last active
July 20, 2017 15:48
-
-
Save naepalm/96fd418a644728a97aa0fa3ebff5c7c8 to your computer and use it in GitHub Desktop.
Grid extensions for use with Ditto, Skybrud, DocType Grid Editor, and the DocType Grid Editor Reusable Content package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web.Mvc; | |
using Our.Umbraco.Ditto; | |
using Offroadcode.Web.Models.Widgets; | |
using Skybrud.Umbraco.GridData; | |
using Skybrud.Umbraco.GridData.Values; | |
using Umbraco.Core.Models; | |
using Umbraco.Web; | |
namespace Offroadcode.Web.Extensions | |
{ | |
public static class GridExtensions | |
{ | |
private static readonly UmbracoHelper _umbraco = new UmbracoHelper(UmbracoContext.Current); | |
public static T GetWidgetControl<T>(this IPublishedContent content) where T : WidgetBaseModel | |
{ | |
// Set a variable to use the default content if no linked content has been selected | |
var widget = content.As<T>(); | |
// Check to see if there's a linked page value | |
if (widget.HasLinkedContentId) | |
{ | |
// Run the linked page value through Umbraco.TypedContent() to get the IPublishedContent page | |
var dtgePage = _umbraco.TypedContent(widget.LinkedContentId); | |
// The value shouldn't ever be null, but weird things happen, so let's just make sure | |
if (dtgePage != null) | |
{ | |
// Set the content to use the linked page instead of the default DTGE values | |
widget = dtgePage.As<T>(); | |
} | |
} | |
return widget; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Our.Umbraco.Ditto; | |
using Umbraco.Core.Models; | |
using Umbraco.Core.Models.PublishedContent; | |
namespace Offroadcode.Web.Models.Widgets | |
{ | |
public class WidgetBaseModel : PublishedContentModel | |
{ | |
public WidgetBaseModel(IPublishedContent content) : base(content) | |
{ | |
} | |
[UmbracoProperty("dtgeLinkedId")] | |
public string LinkedContentId { get; set; } | |
public bool HasLinkedContentId => !string.IsNullOrEmpty(LinkedContentId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment