public static ContentReference GetContentReference(this LinkItem linkItem) { string extension; var guid = PermanentLinkUtility.GetGuid(new UrlBuilder(linkItem.GetMappedHref()), out extension); return(PermanentLinkUtility.FindContentReference(guid)); }
public string GetHref() { if (Type == GroLinkType.ExternalLink || Type == GroLinkType.Email) { return(_linkItem.GetMappedHref()); } var content = GetContent(_linkItem); var link = _linkItem.UrlResolver.Service.GetUrl(content); return(link); }
/// <summary> /// Returns friendly URL if item is EPiServer content, otherwise returns the original Href property value. /// </summary> /// <param name="linkItem">Source LinkItem for which to return external URL.</param> /// <param name="includeHost">Mark if include host name in the url, unless it is external url then it still will contain absolute url</param> /// <returns>Returns friendly URL if item is EPiServer content, otherwise returns the original Href property value.</returns> public static string GetFriendlyUrl(this LinkItem linkItem, bool includeHost = false) { if (string.IsNullOrWhiteSpace(linkItem.Href)) { return(string.Empty); } var url = new Url(linkItem.GetMappedHref()); if (url.IsEmpty()) { return(string.Empty); } var friendlyUrl = url.IsAbsoluteUri ? url.ToString() : UrlResolver.Current.GetUrl(url.ToString()) ?? url.ToString(); return(includeHost && !string.IsNullOrWhiteSpace(friendlyUrl) ? friendlyUrl.AddHost() : friendlyUrl); }
private void ModifyIContentProperties(LinkItem serverModel, ExtendedEPiLinkModel clientModel) { var mappedHref = serverModel.GetMappedHref(); if (string.IsNullOrEmpty(mappedHref)) { return; } var hrefWithoutHash = mappedHref; var anchorOnPage = ""; var indexOfHash = mappedHref.IndexOf('#'); if (indexOfHash > 0) { hrefWithoutHash = mappedHref.Substring(0, indexOfHash - 1); anchorOnPage = mappedHref.Substring(indexOfHash + 1); } clientModel.Href = hrefWithoutHash; clientModel.AnchorOnPage = anchorOnPage; var contentGuid = PermanentLinkUtility.GetGuid(hrefWithoutHash); var contentReference = PermanentLinkUtility.FindContentReference(contentGuid); IContent content; if (!(contentReference != ContentReference.EmptyReference) || !_contentRepository.TryGet(contentReference, out content)) { return; } clientModel.TypeIdentifier = _uiDescriptors.GetTypeIdentifiers(content.GetType()).FirstOrDefault(); var friendlyUrl = _urlHelper.ContentUrl(content.ContentLink); var absoluteUriBySettings = UriSupport.AbsoluteUrlBySettings(friendlyUrl); clientModel.PublicUrl = indexOfHash > 0 ? string.Format("{0}#{1}", absoluteUriBySettings, anchorOnPage) : absoluteUriBySettings; }
private static IContent GetContent(LinkItem linkItem) => linkItem.UrlResolver.Service.Route(new EPiServer.UrlBuilder(linkItem.GetMappedHref()));
/// <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. Note: do not use this to later on generate url as remaining url part will be lost</returns> public static IContent ToContent(this LinkItem source) { var urlBuilder = new UrlBuilder(source.GetMappedHref()); return(UrlResolver.Current.Route(urlBuilder)); }
public static string GetFriendlyUrl(this HtmlHelper helper, LinkItem linkItem) { EPiServer.UrlBuilder url = new EPiServer.UrlBuilder(linkItem.GetMappedHref()); EPiServer.Global.UrlRewriteProvider.ConvertToExternal(url, linkItem.GetMappedHref(), System.Text.UTF8Encoding.UTF8); return url.ToString(); }