Problem/Motivation
When adding a new Media reference field in Field UI via the "Add field" modal and attempting to set a default value via Media Library, MediaLibraryFieldWidgetOpener::checkAccess() fails because it tries to access a field that doesn't exist yet on the entity.
The only workaround is to first create a Media reference field without setting the default value, then right-click the "Edit" button to open the edit form in a new tab where the Media Library modal is stored correctly (instead of the new default behavior which opens in a modal).
This is a separate core bug from the nested modal issue #2741877: Nested modals don't work: opening a modal from a modal closes the original which occurs in a similar scenario when setting the default media from the "Edit field" modal. The MediaLibraryFieldWidgetOpener assumes the field already exists on the entity, which isn't true during initial field creation.
Steps to reproduce
- Add a new Media reference field (field_test_default_media) to a node type.
- During field creation, try to set a default value via Media Library, either via creating a new item, or selecting an existing item from the Media Library modal popup.
- Ajax Error: "Field field_test_default_media is unknown" in ContentEntityBase->getTranslatedField()
Analysis from the Ajax Error stack trace:
- Error location: MediaLibraryFieldWidgetOpener::checkAccess() at line 210 (Drupal 11.3.2)
- Root cause: It calls $entity->get('field_test_default_media') to check field access
- Problem: The field doesn't exist yet because it's being created (not edited)
- Context: The URL shows field_widget_id=field_test_default_media:default_value_input, indicating this is during default value configuration in the "Add Field" workflow.
Proposed resolution
TBD
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3567499-set-default-media-via-field-edit-modal-vs-nonmodal.mov | 25.08 MB | jwilson3 |
| #2 | 3567499-set-default-media-via-field-add-modal.mov | 11.57 MB | jwilson3 |
Comments
Comment #2
jwilson3Comment #3
mortona2k commentedRan into this yesterday.
Comment #4
jwilson3I hit this issue (and #2741877) yesterday while testing a feature request for SVG Image Field #2987590: Support default image fallback for SVG image fields
Comment #5
quietone commentedIssues are fixed on 'main' first.