Issue #3190261 by danflanagan8, doostinharrell, phenaproxima, larowlan, paulocs: MediaLibraryWidget can trigger an AJAX error if all media types can be referenced

(cherry picked from commit 458aa2cb69)
merge-requests/1613/head
catch 2022-01-03 10:51:48 +00:00
parent 5cd38822af
commit 47d0aa0e01
2 changed files with 8 additions and 2 deletions

View File

@ -305,7 +305,8 @@ class MediaLibraryWidget extends WidgetBase implements TrustedCallbackInterface
$element += [
'#type' => 'fieldset',
'#cardinality' => $this->fieldDefinition->getFieldStorageDefinition()->getCardinality(),
'#target_bundles' => $settings['target_bundles'] ?? FALSE,
// If no target bundles are specified, all target bundles are allowed.
'#target_bundles' => $settings['target_bundles'] ?? [],
'#attributes' => [
'id' => $wrapper_id,
'class' => ['js-media-library-widget'],

View File

@ -140,7 +140,12 @@ class EntityReferenceWidgetTest extends MediaLibraryTestBase {
$this->assertTrue($menu->hasLink('Type Three'));
$this->assertTrue($menu->hasLink('Type Four'));
$this->assertTrue($menu->hasLink('Type Five'));
$assert_session->elementExists('css', '.ui-dialog-titlebar-close')->click();
// Insert media to test validation with null target_bundles.
$this->switchToMediaType('One');
$this->assertNotEmpty($assert_session->waitForText('Showing Type One media.'));
$this->selectMediaItem(0);
$this->pressInsertSelected('Added one media item.');
// Assert that the media type menu is not available when only 1 type is
// configured for the field.