diff --git a/src/Umbraco.Web/Models/RelatedLinkBase.cs b/src/Umbraco.Web/Models/RelatedLinkBase.cs index c2077ce4a9..f537d6fca8 100644 --- a/src/Umbraco.Web/Models/RelatedLinkBase.cs +++ b/src/Umbraco.Web/Models/RelatedLinkBase.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Umbraco.Core.Models; namespace Umbraco.Web.Models { @@ -14,5 +15,7 @@ namespace Umbraco.Web.Models public bool IsInternal { get; set; } [JsonProperty("type")] public RelatedLinkType Type { get; set; } + [JsonProperty("content")] + public IPublishedContent Content { get; set; } } } diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksEditorValueConvertor.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksEditorValueConvertor.cs index 4a611dc7be..5f920bfe20 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksEditorValueConvertor.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksEditorValueConvertor.cs @@ -16,6 +16,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.ValueConverters; +using Umbraco.Web.Extensions; using Umbraco.Web.Models; using Umbraco.Web.Routing; @@ -54,7 +55,8 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters { if (UmbracoConfig.For.UmbracoSettings().Content.EnablePropertyValueConverters) { - return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinksAlias); + return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinksAlias) + || propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinks2Alias); } return false; } @@ -83,22 +85,46 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters var sourceString = source.ToString(); - var relatedLinksData = JsonConvert.DeserializeObject>(sourceString); + var relatedLinksData = JsonConvert.DeserializeObject>(sourceString); var relatedLinks = new List(); foreach (var linkData in relatedLinksData) { - var relatedLink = new RelatedLink() + var relatedLink = new RelatedLink { Caption = linkData.Caption, NewWindow = linkData.NewWindow, IsInternal = linkData.IsInternal, Type = linkData.Type, - Id = linkData.Internal, Link = linkData.Link }; - relatedLink = CreateLink(relatedLink); + switch (propertyType.PropertyEditorAlias) + { + case Constants.PropertyEditors.RelatedLinksAlias: + int contentId; + if (int.TryParse(relatedLink.Link, out contentId)) + { + relatedLink.Id = contentId; + relatedLink = CreateLink(relatedLink); + } + break; + case Constants.PropertyEditors.RelatedLinks2Alias: + var strLinkId = linkData.Link; + var udiAttempt = strLinkId.TryConvertTo(); + if (udiAttempt.Success) + { + var content = udiAttempt.Result.ToPublishedContent(); + if (content != null) + { + relatedLink.Id = content.Id; + relatedLink = CreateLink(relatedLink); + relatedLink.Content = content; + } + } + break; + } + if (relatedLink.IsDeleted == false) { relatedLinks.Add(relatedLink); @@ -138,17 +164,5 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters return link; } - - internal class RelatedLinkData : RelatedLinkBase - { - [JsonProperty("internal")] - public int? Internal { get; set; } - [JsonProperty("edit")] - public bool Edit { get; set; } - [JsonProperty("internalName")] - public string InternalName { get; set; } - [JsonProperty("title")] - public string Title { get; set; } - } } } \ No newline at end of file