Code Tidy: Remove obsolete code scheduled for removal in Umbraco 18 (UrlSegment extension method)#22682
Conversation
…ify obsoletion of UrlSegment property for Umbraco 19.
|
Claude finished @AndyButland's task in 5m 4s —— View job PR ReviewTarget: Removes the
Note Complexity advisory — This PR may benefit from splitting.
This is an observation, not a blocker. The full review follows below. Important
Suggestions
Request ChangesThe |
There was a problem hiding this comment.
Pull request overview
This PR continues the v18 obsolete-cleanup by removing the obsolete PublishedContentExtensions.UrlSegment(...) extension method and migrating production + unit test call sites to IDocumentUrlService.GetUrlSegment(...). It also starts deprecating the underlying IPublishedContent.UrlSegment property by adding new [Obsolete] markers and consolidating legacy URL-segment resolution logic into a shared helper.
Changes:
- Removed the obsolete
PublishedContentExtensions.UrlSegment(...)extension method and updated callers to useIDocumentUrlService.GetUrlSegment(...). - Added new
[Obsolete]markers forIPublishedContent.UrlSegmentand implementations, plus introducedPublishedContentUrlSegmentResolverto keep legacy behavior centralized. - Refactored Delivery API unit tests to avoid
IPublishedContent.UrlSegmentand to mockIDocumentUrlServiceinstead.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/PublishedContentCacheTests.cs | Removes UrlSegment-based assertions and updates mocks to align with IDocumentUrlService route resolution. |
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/PropertyValueConverterTests.cs | Stops relying on IPublishedContent.UrlSegment and uses explicit URL return values in provider mocks. |
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/OutputExpansionStrategyTestBase.cs | Removes UrlSegment setup from test scaffolding and updates URL provider mocks accordingly. |
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/MultiNodeTreePickerValueConverterTests.cs | Replaces content.UrlSegment usage with explicit URL segment values in test setup. |
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/MediaBuilderTests.cs | Removes reliance on media.UrlSegment and adjusts media URL provider test setup. |
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/DeliveryApiTests.cs | Refactors shared mock helper to no longer set UrlSegment and adjusts cultures setup. |
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/ContentRouteBuilderTests.cs | Updates route-builder tests to mock IDocumentUrlService.GetUrlSegment(...) and threads the mock through helpers. |
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/ContentPickerValueConverterTests.cs | Replaces content.UrlSegment usage with explicit URL segment values in test URL provider setup. |
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/ContentBuilderTests.cs | Removes UrlSegment reliance in content path/route builder mocks and assertions. |
| src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs | Keeps Razor-facing UrlSegment(...) but routes through the shared resolver and marks it obsolete. |
| src/Umbraco.PublishedCache.HybridCache/PublishedContent.cs | Updates UrlSegment implementation to use shared resolver and refreshes obsolete messaging. |
| src/Umbraco.Core/Security/PublishedExternalMember.cs | Adds [Obsolete] marker to UrlSegment implementation for external members. |
| src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContent.cs | Adds [Obsolete] marker to UrlSegment on internal published content test harness. |
| src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs | Adds [Obsolete] marker and warning suppression around UrlSegment passthrough. |
| src/Umbraco.Core/Models/PublishedContent/PublishedContentUrlSegmentResolver.cs | Introduces shared legacy URL-segment resolution helper (marked obsolete). |
| src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs | Re-implements UrlSegment using shared resolver now that the extension method is removed. |
| src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs | Marks IPublishedContent.UrlSegment obsolete to start deprecation cycle. |
| src/Umbraco.Core/Extensions/PublishedContentExtensions.cs | Removes the obsolete UrlSegment(...) extension method implementation. |
| src/Umbraco.Core/DeliveryApi/ApiContentRouteBuilder.cs | Switches root-path segment resolution to IDocumentUrlService.GetUrlSegment(...) (supports draft in preview). |
| src/Umbraco.Cms.Api.Delivery/Services/RequestStartItemProvider.cs | Injects IDocumentUrlService and uses it for matching the start item by URL segment. |
| src/Umbraco.Cms.Api.Delivery/Services/RequestRedirectService.cs | Injects IDocumentUrlService and uses it for resolving the start-item segment when forming redirect lookup paths. |
…segment to use IDocumentUrlService.
Description
Continues the v18 obsolete-cleanup series. This PR removes the
[Obsolete]UrlSegmentextension method onPublishedContentExtensionsand migrates its callers toIDocumentUrlService.GetUrlSegment().It also starts a clean v20 deprecation cycle for the underlying
IPublishedContent.UrlSegmentproperty — that property on the interface and some of its implementations were never[Obsolete]-marked, so they can't be removed in v18 without violating the deprecation policy.Removed
Umbraco.Cms.Core.Extensions.PublishedContentExtensions.UrlSegment(this IPublishedContent, IVariationContextAccessor?, string?)—[Obsolete("...Scheduled for removal in Umbraco 18.")]. The three production call sites (ApiContentRouteBuilder,RequestStartItemProvider, HybridCachePublishedContent) are migrated toIDocumentUrlService.GetUrlSegment().Migrated to
IDocumentUrlService.GetUrlSegment()src/Umbraco.Core/DeliveryApi/ApiContentRouteBuilder.cs— service was already injected; only the call site changed.src/Umbraco.Cms.Api.Delivery/Services/RequestStartItemProvider.cs— constructor now takesIDocumentUrlService.src/Umbraco.Cms.Api.Delivery/Services/RequestRedirectService.cs— constructor now takesIDocumentUrlService.Re-implemented (no behaviour change for non-preview rendering)
src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs—UrlSegmentbody now delegates to the new shared helper.src/Umbraco.PublishedCache.HybridCache/PublishedContent.cs— same. Also corrected an unrelated stale obsolete message ("Scheduled for removal in V16" was never honoured) to align with the v20 target.src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs— the Razor-facingUrlSegment(this IPublishedContent, string?)wrapper is kept and is not marked as[Obsolete](I'm expecting we'll want to keep this as a convenience). Its body now routes throughIDocumentUrlService.GetUrlSegment()with preview detection viaIUmbracoContextAccessor— so it's consistent with the new deprecation messaging and survives the v20 removal ofIPublishedContent.UrlSegmentunchanged.Shared helper
A new
PublishedContentUrlSegmentResolver.Resolve()static helper consolidates the URL-segment lookup. It also routes throughIDocumentUrlService.GetUrlSegment()(pulled viaStaticServiceProvider) and detects preview state viaIUmbracoContextAccessor.TryGetUmbracoContext(). Marked[Obsolete]because it only exists to satisfy the deprecatedIPublishedContent.UrlSegmentcontract during the v18→v20 deprecation period — removed in v20 alongside the property itself.Routing the resolver through
IDocumentUrlService(rather than readingCultures[culture].UrlSegmentdirectly, as the deleted extension did) keeps the deprecation messaging consistent: every path that ever resolves a URL segment now reads from a single source of truth — the document-URL cache populated byIDocumentUrlService.New
[Obsolete]markers (v20 removal target)Marked
[Obsolete("...Scheduled for removal in Umbraco 20.")]to start a clean deprecation cycle:IPublishedContent.UrlSegment(interface property)PublishedContentWrapped.UrlSegmentInternalPublishedContent.UrlSegment(internal test harness)PublishedExternalMember.UrlSegment(specific message — always returns null for external members)PublishedContent.UrlSegment— already obsolete; only the version target was correctedTest refactoring
The Delivery API tests (
tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/) previously usedIPublishedContent.UrlSegmentheavily as scaffolding — both as a mock-content identity in path-provider lambdas and as the implicit URL-provider return. This PR refactors those tests so:IDocumentUrlService(matches what the production code now reads).ConfigurePublishedContentMockhelper no longer setsc.UrlSegment; theurlSegmentparameter is dropped from its signature and its 14 call sites updated.Assert.AreEqual("...", content.UrlSegment)lines inPublishedContentCacheTestsare removed (the same tests already verify content identity viaKeyandContentType.Alias).End result: zero
IPublishedContent.UrlSegmentreferences in the Delivery API test folder. When the property is removed in v20, no further test changes are needed.Behaviour note: preview mode
The new code passes
isDraft(derived from preview state) toGetUrlSegment()consistently across all migrated paths:ApiContentRouteBuilderandRequestStartItemProvideruseIRequestPreviewService.IsPreview()(already injected).PublishedContentUrlSegmentResolver(and thereforePublishedContentBase.UrlSegment, HybridCachePublishedContent.UrlSegment, andFriendlyPublishedContentExtensions.UrlSegment) detect preview state via the ambientIUmbracoContext.InPreviewMode.RequestRedirectServicecorrectly usesisDraft: false— URL tracking is published-only.The deleted extension method always returned the published URL segment regardless of preview state (it read from
IPublishedContent.Cultures, which only ever exposed published data). So in preview mode, route building and the Razor@Model.UrlSegment()helper now return the draft URL segment where they previously returned the published one. This is more correct (preview should preview the draft URL).Breaking changes
PublishedContentExtensions.UrlSegment(this IPublishedContent, IVariationContextAccessor?, string?)extension method is removed. External callers should switch toIDocumentUrlService.GetUrlSegment(documentKey, culture, isDraft).IPublishedContent.UrlSegment(interface property) and the four remaining implementations (PublishedContentWrapped,InternalPublishedContent,PublishedExternalMember, HybridCachePublishedContent) are now[Obsolete]and emit CS0618 warnings when consumed. The property remains functional in v18.FriendlyPublishedContentExtensions.UrlSegment(this IPublishedContent, string?)is not obsolete — Razor templates calling@Model.UrlSegment(culture)keep working and require no migration.Testing
Solution builds and tests pass.
Can also use the following Razor code to verify that the different, existing methods for retrieving URL segments reveal the same result: