Skip to content

Elements: Fix GetUdi() extension methods for Element entities#22873

Merged
AndyButland merged 1 commit into
release/18.0from
v18/hotfix/getudi-ielement
May 18, 2026
Merged

Elements: Fix GetUdi() extension methods for Element entities#22873
AndyButland merged 1 commit into
release/18.0from
v18/hotfix/getudi-ielement

Conversation

@ronaldbarendse

Copy link
Copy Markdown
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

Description

Adds the missing GetUdi() overloads for IElement, so v18 Global Elements (Library section) can produce their umb://element/{key} identifier through the same extension surface used for documents, media and members.

The gap

UdiGetterExtensions.GetUdi(this IContentBase) switches on IContent/IMedia/IMember and throws NotSupportedException for anything else - including IElement, which inherits from IPublishableContentBase : IContentBase. The same path is reached via GetUdi(this IEntity), which dispatches IContentBase instances down to the same switch.

This is part of a recurring pattern with this extension class missing new entity types - prior fixes:

Changes

  • UdiGetterExtensions.GetUdi(this IContentBase) - new IElement case (cases reordered alphabetically).
  • New UdiGetterExtensions.GetUdi(this IElement) returning new GuidUdi(Constants.UdiEntityType.Element, entity.Key) (i.e. umb://element/{key}).
  • UdiGetterExtensionsTests - new GetUdiForElement test covering direct, IContentBase, and IEntity dispatch; GetUdiForEntityContainer extended with an Element test case (already worked via EntityContainer.GetUdi(), now locked in).

Testing

  • dotnet test --filter UdiGetterExtensionsTests - 34/34 pass.
  • Manual: ((IContentBase)element).GetUdi() no longer throws NotSupportedException.
  • Manual: all three dispatch paths (IElement, IContentBase, IEntity) return the same umb://element/{key} UDI.

Adds the missing GetUdi() overloads for IElement so v18 Global Elements
produce their umb://element/{key} identifier through the same extension
surface used for documents, media and members.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 18, 2026 12:01
@claude

claude Bot commented May 18, 2026

Copy link
Copy Markdown

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds missing UDI support for IElement entities so elements (Global Elements / Library) can produce umb://element/{key} consistently via the existing GetUdi() extension surface (directly and through IContentBase / IEntity dispatch).

Changes:

  • Extend UdiGetterExtensions.GetUdi(this IContentBase) to support IElement.
  • Add GetUdi(this IElement) overload returning a GuidUdi with Constants.UdiEntityType.Element.
  • Add/extend unit tests to cover element UDIs and ensure all dispatch paths return the same value.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Umbraco.Core/Extensions/UdiGetterExtensions.cs Adds IElement UDI generation and routes IContentBase.GetUdi() to it.
tests/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UdiGetterExtensionsTests.cs Adds element UDI test coverage (direct + interface dispatch) and extends container test cases.

@AndyButland AndyButland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ronaldbarendse - all looks good to handle these cases.

@AndyButland AndyButland merged commit cd1524f into release/18.0 May 18, 2026
29 of 30 checks passed
@AndyButland AndyButland deleted the v18/hotfix/getudi-ielement branch May 18, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants