Skip to content

Commit

Permalink
Merge pull request #8 from valdisiljuconoks/master
Browse files Browse the repository at this point in the history
Fixed issue to convert LinkItem to ContentReference
  • Loading branch information
frederikvig committed May 15, 2015
2 parents ed660c5 + 242e3db commit 9e94b21
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions Geta.EPi.Extensions/LinkItemExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using EPiServer;
using EPiServer.Core;
using EPiServer.ServiceLocation;
using EPiServer.SpecializedProperties;
using EPiServer.Web;
using EPiServer.Web.Routing;

namespace Geta.EPi.Extensions
{
Expand All @@ -11,16 +12,29 @@ namespace Geta.EPi.Extensions
public static class LinkItemExtensions
{
/// <summary>
/// Returns ContentReference for provided LinkItem if it is EPiServer page otherwise returns EmptyReference.
/// Returns ContentReference for provided LinkItem if it is EPiServer content otherwise returns EmptyReference.
/// </summary>
/// <param name="source">Source LinkItem for which to return content reference.</param>
/// <returns>Returns ContentReference for provided LinkItem if it is EPiServer page otherwise returns EmptyReference.</returns>
/// <returns>Returns ContentReference for provided LinkItem if it is EPiServer content otherwise returns EmptyReference.</returns>
public static ContentReference ToContentReference(this LinkItem source)
{
var content = source.ToContent();

return content != null
? content.ContentLink
: ContentReference.EmptyReference;
}

/// <summary>
/// Returns IContent for provided LinkItem if it is EPiServer content otherwise returns null.
/// </summary>
/// <param name="source">Source LinkItem for which to return content.</param>
/// <returns>Returns IContent for provided LinkItem if it is EPiServer content otherwise returns null.</returns>
public static IContent ToContent(this LinkItem source)
{
var urlBuilder = new UrlBuilder(source.Href);
return PermanentLinkMapStore.ToMapped(urlBuilder)
? PermanentLinkUtility.GetContentReference(urlBuilder)
: ContentReference.EmptyReference;
var resolver = ServiceLocator.Current.GetInstance<UrlResolver>();
return resolver.Route(urlBuilder);
}
}
}
}

0 comments on commit 9e94b21

Please sign in to comment.