diff --git a/src/Umbraco.Core/Routing/UrlProviderExtensions.cs b/src/Umbraco.Core/Routing/UrlProviderExtensions.cs index 8e2a577f3a..6f3cd05c9b 100644 --- a/src/Umbraco.Core/Routing/UrlProviderExtensions.cs +++ b/src/Umbraco.Core/Routing/UrlProviderExtensions.cs @@ -1,5 +1,7 @@ +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Umbraco.Cms.Core; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Cms.Core.Routing; @@ -10,13 +12,7 @@ namespace Umbraco.Extensions; public static class UrlProviderExtensions { - /// - /// Gets the URLs of the content item. - /// - /// - /// Use when displaying URLs. If errors occur when generating the URLs, they will show in the list. - /// Contains all the URLs that we can figure out (based upon domains, etc). - /// + [Obsolete("Use GetContentUrlsAsync that takes ILanguageService instead of ILocalizationService. Will be removed in V15.")] public static async Task> GetContentUrlsAsync( this IContent content, IPublishedRouter publishedRouter, @@ -28,11 +24,40 @@ public static class UrlProviderExtensions ILogger logger, UriUtility uriUtility, IPublishedUrlProvider publishedUrlProvider) + => await content.GetContentUrlsAsync( + publishedRouter, + umbracoContext, + StaticServiceProvider.Instance.GetRequiredService(), + textService, + contentService, + variationContextAccessor, + logger, + uriUtility, + publishedUrlProvider); + + /// + /// Gets the URLs of the content item. + /// + /// + /// Use when displaying URLs. If errors occur when generating the URLs, they will show in the list. + /// Contains all the URLs that we can figure out (based upon domains, etc). + /// > GetContentUrlsAsync( + this IContent content, + IPublishedRouter publishedRouter, + IUmbracoContext umbracoContext, + ILanguageService languageService, + ILocalizedTextService textService, + IContentService contentService, + IVariationContextAccessor variationContextAccessor, + ILogger logger, + UriUtility uriUtility, + IPublishedUrlProvider publishedUrlProvider) { ArgumentNullException.ThrowIfNull(content); ArgumentNullException.ThrowIfNull(publishedRouter); ArgumentNullException.ThrowIfNull(umbracoContext); - ArgumentNullException.ThrowIfNull(localizationService); + ArgumentNullException.ThrowIfNull(languageService); ArgumentNullException.ThrowIfNull(textService); ArgumentNullException.ThrowIfNull(contentService); ArgumentNullException.ThrowIfNull(variationContextAccessor); @@ -60,7 +85,7 @@ public static class UrlProviderExtensions // and, not only for those assigned to domains in the branch, because we want // to show what GetUrl() would return, for every culture. var urls = new HashSet(); - var cultures = localizationService.GetAllLanguages().Select(x => x.IsoCode).ToList(); + var cultures = (await languageService.GetAllAsync()).Select(x => x.IsoCode).ToList(); // get all URLs for all cultures // in a HashSet, so de-duplicates too diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UrlAndDomains/DomainAndUrlsTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UrlAndDomains/DomainAndUrlsTests.cs index 85f0f7439c..c5bee58962 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UrlAndDomains/DomainAndUrlsTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UrlAndDomains/DomainAndUrlsTests.cs @@ -139,7 +139,7 @@ public class DomainAndUrlsTests : UmbracoIntegrationTest root.GetContentUrlsAsync( GetRequiredService(), GetRequiredService().GetRequiredUmbracoContext(), - GetRequiredService(), + GetRequiredService(), GetRequiredService(), ContentService, GetRequiredService(), diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/GetContentUrlsTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/GetContentUrlsTests.cs index 8f1fceb615..8a7f2ff66f 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/GetContentUrlsTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/GetContentUrlsTests.cs @@ -1,7 +1,4 @@ -using System.Collections.Generic; using System.Globalization; -using System.Linq; -using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; @@ -58,16 +55,16 @@ public class GetContentUrlsTests : PublishedSnapshotServiceTestBase return textService.Object; } - private ILocalizationService GetLangService(params string[] isoCodes) + private ILanguageService GetLangService(params string[] isoCodes) { var allLangs = isoCodes .Select(CultureInfo.GetCultureInfo) .Select(culture => new Language(culture.Name, culture.EnglishName) { IsDefault = true, IsMandatory = true }) .ToArray(); - var langServiceMock = new Mock(); - langServiceMock.Setup(x => x.GetAllLanguages()).Returns(allLangs); - langServiceMock.Setup(x => x.GetDefaultLanguageIsoCode()).Returns(allLangs.First(x => x.IsDefault).IsoCode); + var langServiceMock = new Mock(); + langServiceMock.Setup(x => x.GetAllAsync()).ReturnsAsync(allLangs); + langServiceMock.Setup(x => x.GetDefaultIsoCodeAsync()).ReturnsAsync(allLangs.First(x => x.IsDefault).IsoCode); return langServiceMock.Object; }