Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Umbraco.Core/Models/ContentEditing/LinkDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class LinkDisplay
[DataMember(Name = "name")]
public string? Name { get; set; }

[DataMember(Name = "nodeName")]
public string? NodeName { get; set; }

[DataMember(Name = "published")]
public bool Published { get; set; }

Expand Down
4 changes: 4 additions & 0 deletions src/Umbraco.Core/Models/Link.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Umbraco.Cms.Core.Models.PublishedContent;

namespace Umbraco.Cms.Core.Models;

public class Link
Expand All @@ -10,5 +12,7 @@ public class Link

public Udi? Udi { get; set; }

public IPublishedContent? Content { get; set; }

public string? Url { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Web.Common.DependencyInjection;
using Umbraco.Extensions;

namespace Umbraco.Cms.Core.PropertyEditors;

Expand Down Expand Up @@ -146,51 +147,55 @@ public IEnumerable<UmbracoEntityReference> GetReferences(object? value)

foreach (LinkDto dto in links)
{
GuidUdi? udi = dto.Udi;
var icon = "icon-link";
string? nodeName = null;
var published = true;
var trashed = false;
var url = dto.Url;

if (dto.Udi != null)
if (dto.Udi is not null)
{
if (dto.Udi.EntityType == Constants.UdiEntityType.Document)
{
url = _publishedUrlProvider.GetUrl(dto.Udi.Guid, UrlMode.Relative, culture);
IContent? c = _contentService.GetById(dto.Udi.Guid);

if (c is not null)
IContent? content = _contentService.GetById(dto.Udi.Guid);
if (content is not null)
{
icon = content.ContentType.Icon;
nodeName = content.Name;
published = culture == null
? c.Published
: c.PublishedCultures.Contains(culture);
icon = c.ContentType.Icon;
trashed = c.Trashed;
? content.Published
: content.IsCulturePublished(culture);
trashed = content.Trashed;
}

url = _publishedUrlProvider.GetUrl(dto.Udi.Guid, UrlMode.Relative, culture);
}
else if (dto.Udi.EntityType == Constants.UdiEntityType.Media)
{
url = _publishedUrlProvider.GetMediaUrl(dto.Udi.Guid, UrlMode.Relative, culture);
IMedia? m = _mediaService.GetById(dto.Udi.Guid);
if (m is not null)
IMedia? media = _mediaService.GetById(dto.Udi.Guid);
if (media is not null)
{
published = m.Trashed is false;
icon = m.ContentType.Icon;
trashed = m.Trashed;
icon = media.ContentType.Icon;
nodeName = media.Name;
published = media.Trashed is false;
trashed = media.Trashed;
}

url = _publishedUrlProvider.GetMediaUrl(dto.Udi.Guid, UrlMode.Relative, culture);
}
}

result.Add(new LinkDisplay
{
Icon = icon,
Name = dto.Name,
Target = dto.Target,
Trashed = trashed,
NodeName = nodeName,
Published = published,
QueryString = dto.QueryString,
Udi = udi,
Url = url ?? string.Empty,
Target = dto.Target,
Trashed = trashed,
Udi = dto.Udi,
Url = url,
});
}

Expand Down Expand Up @@ -229,7 +234,7 @@ from link in links
QueryString = link.QueryString,
Target = link.Target,
Udi = link.Udi,
Url = link.Udi == null ? link.Url : null, // only save the URL for external links
Url = link.Udi is null ? link.Url : null, // only save the URL for external links
},
_linkDisplayJsonSerializerSettings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType
{
LinkType type = LinkType.External;
var url = dto.Url;
var name = dto.Name;
IPublishedContent? content = null;

if (dto.Udi is not null)
{
type = dto.Udi.EntityType == Constants.UdiEntityType.Media
? LinkType.Media
: LinkType.Content;

IPublishedContent? content = type == LinkType.Media
content = type == LinkType.Media
? publishedSnapshot.Media?.GetById(preview, dto.Udi.Guid)
: publishedSnapshot.Content?.GetById(preview, dto.Udi.Guid);

Expand All @@ -123,16 +125,22 @@ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType
continue;
}

if (string.IsNullOrEmpty(name))
{
name = content.Name;
}

url = content.Url(_publishedUrlProvider);
}

links.Add(
new Link
{
Name = dto.Name,
Name = name,
Target = dto.Target,
Type = type,
Udi = dto.Udi,
Content = content,
Url = url + dto.QueryString,
});
}
Expand Down
Loading