diff --git a/core/modules/media_library/css/media_library.theme.css b/core/modules/media_library/css/media_library.theme.css index f8b127ad22..dfe8a72108 100644 --- a/core/modules/media_library/css/media_library.theme.css +++ b/core/modules/media_library/css/media_library.theme.css @@ -139,15 +139,11 @@ /* Media add form selection styles. */ .media-library-add-form__selected-media { - margin-top: 1em; + margin: 1em -8px 0 -8px; padding-top: 1em; border-top: 1px solid #c0c0c0; } -.media-library-add-form__selected-media .media-library-item { - width: 120px; -} - .media-library-add-form__selected-media .media-library-item .field--name-thumbnail img { height: 100px; } @@ -286,16 +282,26 @@ border: 1px solid #dbdbdb; } +/* The selected items in the add form should be shown a bit smaller. */ +.media-library-add-form__selected-media .media-library-item--grid { + width: 33.3%; +} + @media screen and (min-width: 45em) { .media-library-item--grid { - width: 33%; + width: 33.3%; } - /* Use a smaller width for the modal and widget since there is less space. */ + /* Change the width for the modal and widget since there is less space. */ .media-library-widget-modal .media-library-item--grid, .media-library-selection .media-library-item--grid { width: 50%; } + + /* The selected items in the add form should be shown a bit smaller. */ + .media-library-add-form__selected-media .media-library-item--grid { + width: 25%; + } } @media screen and (min-width: 60em) { @@ -303,23 +309,33 @@ width: 25%; } - /* Use a smaller width for the modal and widget since there is less space. */ + /* Change the width for the modal and widget since there is less space. */ .media-library-widget-modal .media-library-item--grid, .media-library-selection .media-library-item--grid { - width: 33%; + width: 33.3%; + } + + /* The selected items in the add form should be shown a bit smaller. */ + .media-library-add-form__selected-media .media-library-item--grid { + width: 16.6%; } } @media screen and (min-width: 77em) { .media-library-item--grid { - width: 16%; + width: 16.6%; } - /* Use a smaller width for the modal and widget since there is less space. */ + /* Change the width for the modal and widget since there is less space. */ .media-library-widget-modal .media-library-item--grid, .media-library-selection .media-library-item--grid { width: 25%; } + + /* The selected items in the add form should be shown a bit smaller. */ + .media-library-add-form__selected-media .media-library-item--grid { + width: 16.6%; + } } .media-library-item--grid .field--name-thumbnail { @@ -344,7 +360,7 @@ border-radius: 3px; } -.media-library-item--grid.checked { +.media-library-item--grid.checked:before { border-color: #0076c0; } diff --git a/core/modules/media_library/src/Form/AddFormBase.php b/core/modules/media_library/src/Form/AddFormBase.php index 6ea135a5ba..788b14208d 100644 --- a/core/modules/media_library/src/Form/AddFormBase.php +++ b/core/modules/media_library/src/Form/AddFormBase.php @@ -592,7 +592,7 @@ public function updateWidget(array &$form, FormStateInterface $form_state) { } // Pass the selection to the field widget based on the current widget ID. - $opener_id = MediaLibraryState::fromRequest($this->getRequest())->getOpenerId(); + $opener_id = $this->getMediaLibraryState($form_state)->getOpenerId(); if ($field_id = MediaLibraryWidget::getOpenerFieldId($opener_id)) { // The added media items get an ID when they are saved in ::submitForm(). // For that reason the added media items are keyed by delta in the form diff --git a/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php index fcc3fff4e2..f5893c33ca 100644 --- a/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php @@ -729,7 +729,7 @@ public function testWidgetUpload() { $assert_session->pageTextNotContains($png_image->filename); // Assert we can also directly insert uploaded files in the widget. - $assert_session->elementExists('css', '.media-library-open-button[href*="field_twin_media"]')->click(); + $assert_session->elementExists('css', '.media-library-open-button[name^="field_twin_media"]')->click(); $assert_session->assertWaitOnAjaxRequest(); $assert_session->pageTextContains('Add or select media'); $page->clickLink('Type Three'); @@ -803,7 +803,7 @@ public function testWidgetUpload() { $assert_session->pageTextContains('Unlimited Cardinality Image'); // Assert we can now only upload one more media item. - $assert_session->elementExists('css', '.media-library-open-button[href*="field_twin_media"]')->click(); + $assert_session->elementExists('css', '.media-library-open-button[name^="field_twin_media"]')->click(); $assert_session->assertWaitOnAjaxRequest(); $assert_session->pageTextContains('Add or select media'); $page->clickLink('Type Four'); @@ -845,7 +845,7 @@ public function testWidgetUpload() { // Assert we can also remove selected items from the selection area in the // upload form. - $assert_session->elementExists('css', '.media-library-open-button[href*="field_unlimited_media"]')->click(); + $assert_session->elementExists('css', '.media-library-open-button[name^="field_unlimited_media"]')->click(); $assert_session->assertWaitOnAjaxRequest(); $assert_session->pageTextContains('Add or select media'); $page->clickLink('Type Three'); @@ -1013,7 +1013,7 @@ public function testWidgetOEmbed() { $assert_session->pageTextContains('Custom video title'); // Assert we can directly insert added oEmbed media in the widget. - $assert_session->elementExists('css', '.media-library-open-button[href*="field_unlimited_media"]')->click(); + $assert_session->elementExists('css', '.media-library-open-button[name^="field_unlimited_media"]')->click(); $assert_session->assertWaitOnAjaxRequest(); $assert_session->pageTextContains('Add or select media'); $page->clickLink('Type Five'); @@ -1028,7 +1028,7 @@ public function testWidgetOEmbed() { // Assert we can remove selected items from the selection area in the oEmbed // form. - $assert_session->elementExists('css', '.media-library-open-button[href*="field_unlimited_media"]')->click(); + $assert_session->elementExists('css', '.media-library-open-button[name^="field_unlimited_media"]')->click(); $assert_session->assertWaitOnAjaxRequest(); $assert_session->pageTextContains('Add or select media'); $page->clickLink('Type Five');