Skip to content

Commit

Permalink
Add logic for UrlSegments back
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeegaan committed Oct 25, 2024
1 parent 5a5de18 commit c54557d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/Umbraco.Core/Extensions/PublishedContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static string Name(this IPublishedContent content, IVariationContextAcces
/// The specific culture to get the URL segment for. If null is used the current culture is used
/// (Default is null).
/// </param>
[Obsolete("Please use GetUrlSegment() on IDocumentUrlService instead. Scheduled for removal in V16.")]
public static string? UrlSegment(this IPublishedContent content, IVariationContextAccessor? variationContextAccessor, string? culture = null)
{
if (content == null)
Expand All @@ -89,10 +90,8 @@ public static string Name(this IPublishedContent content, IVariationContextAcces
culture = variationContextAccessor?.VariationContext?.Culture ?? string.Empty;
}

// get
return culture != string.Empty && content.Cultures.TryGetValue(culture, out PublishedCultureInfo? infos)
? infos.UrlSegment
: null;
IDocumentUrlService documentUrlService = StaticServiceProvider.Instance.GetRequiredService<IDocumentUrlService>();
return documentUrlService.GetUrlSegment(content.Key, culture, content.IsDraft());
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public abstract class PublishedContentBase : IPublishedContent
public virtual string Name => this.Name(_variationContextAccessor);

/// <inheritdoc />
[Obsolete("Please use GetUrlSegment() on IDocumentUrlService instead. Scheduled for removal in V16.")]
public virtual string? UrlSegment => this.UrlSegment(_variationContextAccessor);

/// <inheritdoc />
Expand Down Expand Up @@ -75,7 +76,6 @@ public abstract class PublishedContentBase : IPublishedContent
[Obsolete("Please use TryGetParentKey() on IDocumentNavigationQueryService or IMediaNavigationQueryService instead. Scheduled for removal in V16.")]
public abstract IPublishedContent? Parent { get; }

// FIXME
/// <inheritdoc />
[Obsolete("Please use TryGetChildrenKeys() on IDocumentNavigationQueryService or IMediaNavigationQueryService instead. Scheduled for removal in V16.")]
public virtual IEnumerable<IPublishedContent> Children => GetChildren();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using StackExchange.Profiling.Internal;
using Umbraco.Cms.Core.Media.EmbedProviders;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
using Umbraco.Extensions;

Expand All @@ -10,11 +9,13 @@ internal class CacheNodeFactory : ICacheNodeFactory
{
private readonly IShortStringHelper _shortStringHelper;
private readonly UrlSegmentProviderCollection _urlSegmentProviders;
private readonly IDocumentUrlService _documentUrlService;

public CacheNodeFactory(IShortStringHelper shortStringHelper, UrlSegmentProviderCollection urlSegmentProviders)
public CacheNodeFactory(IShortStringHelper shortStringHelper, UrlSegmentProviderCollection urlSegmentProviders, IDocumentUrlService documentUrlService)
{
_shortStringHelper = shortStringHelper;
_urlSegmentProviders = urlSegmentProviders;
_documentUrlService = documentUrlService;
}

public ContentCacheNode ToContentCacheNode(IContent content, bool preview)
Expand Down Expand Up @@ -126,6 +127,7 @@ private ContentData GetContentData(IContentBase content, bool published, int? te
}

var cultureData = new Dictionary<string, CultureVariation>();
string? urlSegment = null;

// sanitize - names should be ok but ... never knows
if (content.ContentType.VariesByCulture())
Expand Down Expand Up @@ -153,10 +155,14 @@ private ContentData GetContentData(IContentBase content, bool published, int? te
}
}
}
else
{
urlSegment = content.GetUrlSegment(_shortStringHelper, _urlSegmentProviders);
}

return new ContentData(
content.Name,
null,
urlSegment,
content.VersionId,
content.UpdateDate,
content.CreatorId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,7 @@ private ContentNuDto GetDtoFromContent(IContentBase content, bool published, ICo
cultureData[cultureInfo.Culture] = new CultureVariation
{
Name = cultureInfo.Name,
UrlSegment =
content.GetUrlSegment(_shortStringHelper, _urlSegmentProviders, cultureInfo.Culture),
UrlSegment = content.GetUrlSegment(_shortStringHelper, _urlSegmentProviders, cultureInfo.Culture),
Date = content.GetUpdateDate(cultureInfo.Culture) ?? DateTime.MinValue,
IsDraft = cultureIsDraft,
};
Expand Down Expand Up @@ -843,7 +842,7 @@ private ContentCacheNode CreateContentNodeKit(ContentSourceDto dto, IContentCach
serializer.Deserialize(dto, dto.EditData, dto.EditDataRaw, published);
var draftContentData = new ContentData(
dto.EditName,
null,
deserializedDraftContent?.UrlSegment,
dto.VersionId,
dto.EditVersionDate,
dto.CreatorId,
Expand Down Expand Up @@ -882,7 +881,7 @@ private ContentCacheNode CreateContentNodeKit(ContentSourceDto dto, IContentCach
ContentCacheDataModel? deserializedContent = serializer.Deserialize(dto, dto.PubData, dto.PubDataRaw, true);
var publishedContentData = new ContentData(
dto.PubName,
null,
deserializedContent?.UrlSegment,
dto.VersionId,
dto.PubVersionDate,
dto.CreatorId,
Expand Down

0 comments on commit c54557d

Please sign in to comment.