Media Picker: Allow folder selection in media entity picker (closes #21885)#21895
Conversation
There was a problem hiding this comment.
Pull request overview
Adds configurable folder selectability to the shared media picker input/context so folder selection can be enabled for the Media Entity Picker (used by RTE “Image Upload Folder” and Media Picker “Start node”) while preserving the existing “files only” behavior elsewhere (e.g., link-to-media scenarios).
Changes:
- Introduces
UmbMediaPickerFolderFilterand applies it inUmbMediaPickerInputContext’spickableFilter. - Adds a
folderFilterproperty/attribute to<umb-input-media>and forwards it into the picker context. - Sets
folderFiltertoFOLDERS_ONLYin the Media Entity Picker property editor.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Umbraco.Web.UI.Client/src/packages/media/media/property-editors/media-entity-picker/property-editor-ui-media-entity-picker.element.ts | Forces folder-only selection mode for the Media Entity Picker by setting folderFilter. |
| src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-media/input-media.element.ts | Adds folderFilter API on the element and forwards it when opening the picker. |
| src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-media/input-media.context.ts | Implements folder filtering logic inside the shared media picker pickableFilter. |
Comments suppressed due to low confidence (2)
src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-media/input-media.context.ts:91
- The
allowedContentTypescheck is still applied after the folder filter. IffolderFilteris set toFOLDERS_ONLYorFILES_AND_FOLDERSandallowedContentTypesis provided (common when restricting media types), folders will almost always be rejected because the folder media type isn’t included inallowedContentTypes. Consider applyingallowedContentTypesfiltering only to non-folder items (or otherwise exempting folders) so the new folder filter modes behave as expected.
const isFolder = isUmbracoFolder(item.mediaType.unique);
// Apply folder filter
if (folderFilter === UmbMediaPickerFolderFilter.FILES_ONLY && isFolder) {
return false;
}
if (folderFilter === UmbMediaPickerFolderFilter.FOLDERS_ONLY && !isFolder) {
return false;
}
// FILES_AND_FOLDERS — no folder-level filtering
if (allowedContentTypes && allowedContentTypes.length > 0) {
return allowedContentTypes
.map((contentTypeReference) => contentTypeReference.unique)
.includes(item.mediaType.unique);
}
src/Umbraco.Web.UI.Client/src/packages/media/media/property-editors/media-entity-picker/property-editor-ui-media-entity-picker.element.ts:3
UmbMediaPickerFolderFilteris already re-exported via../../components/index.js(throughinput-media/index.ts). Importing it directly from../../components/input-media/input-media.context.jscreates an unnecessary deep import and makes the property editor more coupled to internal file structure; consider importing it from the components barrel to keep imports consistent.
import { UmbMediaPickerFolderFilter } from '../../components/input-media/input-media.context.js';
import type { UmbInputMediaElement } from '../../components/index.js';
import { UmbChangeEvent } from '@umbraco-cms/backoffice/event';
leekelleher
left a comment
There was a problem hiding this comment.
Tested out, works as described. 🚀
|
Tests good ✅ |
|
This pull request has been mentioned on Umbraco community forum. There might be relevant details there: |
|
This pull request has been mentioned on Umbraco community forum. There might be relevant details there: |
Description
This PR addresses #21885 which shows a regression coming from #21678, which added an folder exclusion to the shared
#pickableFilterinUmbMediaPickerInputContext. This correctly prevented folder selection in the link picker which was the intention, but also caused this problem, where folders are the intended selection target.To resolve I've introduced a
UmbMediaPickerFolderFilterenum (FILES_ONLY,FOLDERS_ONLY,FILES_AND_FOLDERS) to make folder selectability configurable per media picker instance.This is passed through
umb-input-mediaelement and its picker context, defaulting toFILES_ONLY(preserving existing behaviour).But we set
FOLDERS_ONLYon theMediaEntityPickerso RTE "Image Upload Folder" and Media Picker "Start node" configs can select folders again.Test plan
To manually test, create a media folder and some files in the Media section, then verify the following: