Skip to content

Media Types: Add public constant for Folder media type GUID#21597

Merged
AndyButland merged 2 commits intomainfrom
v17/improvement/public-constant-for-folder-media-type
Feb 3, 2026
Merged

Media Types: Add public constant for Folder media type GUID#21597
AndyButland merged 2 commits intomainfrom
v17/improvement/public-constant-for-folder-media-type

Conversation

@AndyButland
Copy link
Contributor

@AndyButland AndyButland commented Feb 2, 2026

Description

Follows up on #21461 and in particular the comment #21461 (comment) which created constants for media type GUID identifiers.

This earler PR missed the "Folder" media type though, so I've added it in here.

Change Summary

  • Adds Folder and FolderGuid constants to Constants.MediaTypes.Guids for consistency with other media types (Article, Audio, File, Image, Svg, Video)
  • Updates DatabaseDataCreator and EnsureDefaultMediaFolderHasDefaultCollection migration to use the new constant instead of hardcoded GUIDs

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds public constants for the Folder media type GUID to improve consistency and maintainability across the codebase. The Folder media type was previously using hardcoded GUID values while other media types (Article, Audio, File, Image, Svg, Video) already had defined constants.

Changes:

  • Added Folder (string) and FolderGuid (Guid) constants to Constants.MediaTypes.Guids class
  • Replaced hardcoded GUID string in DatabaseDataCreator.CreateNodeDataForMediaTypes() with the new constants
  • Replaced hardcoded GUID in the EnsureDefaultMediaFolderHasDefaultCollection migration with the new constant

Reviewed changes

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

File Description
src/Umbraco.Core/Constants-MediaTypes.cs Adds Folder and FolderGuid constants following the established pattern for other media types
src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs Replaces hardcoded GUID with new constants in Folder media type creation
src/Umbraco.Infrastructure/Migrations/Upgrade/V_17_0_0/EnsureDefaultMediaFolderHasDefaultCollection.cs Replaces hardcoded GUID with FolderGuid constant in migration

@arknu
Copy link
Contributor

arknu commented Feb 2, 2026

@AndyButland Thanks. Can you modify my code here in this PR as well? It currently does a lookup, but there is no need to since the ID is constant and known:

if (allowedMediaTypes is not null)
{
IMediaType? folderMediaType = _mediaTypeService.Get(Constants.Conventions.MediaTypes.Folder);
if (folderMediaType is not null && allowedMediaTypes.Contains(folderMediaType.Key) is false)
{
allowedMediaTypes = [..allowedMediaTypes, folderMediaType.Key];
}
}

From PR #21216

Alternatively, I can submit my own PR to do that, if you think that is better. Just want to make sure we get the most performant implementation for 17.2.

@AndyButland
Copy link
Contributor Author

@arknu - thanks, I've updated to use the known folder key here too.

@AndyButland AndyButland merged commit 9915fd3 into main Feb 3, 2026
26 checks passed
@AndyButland AndyButland deleted the v17/improvement/public-constant-for-folder-media-type branch February 3, 2026 08:16
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.

3 participants