- Issue created by @coreymacmullin
When using Media Library Extend in conjunction with Media Library Form API users are unable to open the media library dialog when following the allowed bundles single dimension array formatting.
$form['image'] = [
'#type' => 'media_library',
'#allowed_bundles' => ['image'],
'#title' => t('Upload your image'),
'#default_value' => NULL|1|'1,2,3',
'#description' => t('Upload or select your profile image.'),
];
Users must instead supply a key/value pair of strings like so:
$form['image'] = [
'#type' => 'media_library',
'#allowed_bundles' => ['image' => 'image'],
'#title' => t('Upload your image'),
'#default_value' => NULL|1|'1,2,3',
'#description' => t('Upload or select your profile image.'),
];
The issue starts at line 102 of the MediaLibraryExtendUiBuilder.php. The key of the array is appended to the end, causing the $allowed_media_type_ids check in media_library/src/MediaLibrary.php to fail as its looking for a string and instead finds an int. Uninstalling Media Library Extend also resolves the issue.
Install both Media Library Extend and Media Library Form API. Build a media_type form element and click "Add Media" button to trigger Media Library modal. Modal will fail to open and return an AJAX error as well as log message stating:
InvalidArgumentException: The allowed types parameter is required and must be an array of strings. in Drupal\media_library\MediaLibraryState->validateRequiredParameters() (line 152 of /var/www/html/web/core/modules/media_library/src/MediaLibraryState.php).
Active
2.1
Code