diff --git a/core/modules/media/src/MediaSourceBase.php b/core/modules/media/src/MediaSourceBase.php index 83288996c69715d865c3083286480267bb6693e2..1edc8584508e693a6ee274ac328afaa7edaccfd7 100644 --- a/core/modules/media/src/MediaSourceBase.php +++ b/core/modules/media/src/MediaSourceBase.php @@ -344,7 +344,12 @@ public function prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayIn * {@inheritdoc} */ public function prepareFormDisplay(MediaTypeInterface $type, EntityFormDisplayInterface $display) { - $display->setComponent($this->getSourceFieldDefinition($type)->getName()); + // Make sure the source field is placed just after the "name" basefield. + $name_component = $display->getComponent('name'); + $source_field_weight = ($name_component && isset($name_component['weight'])) ? $name_component['weight'] + 5 : -50; + $display->setComponent($this->getSourceFieldDefinition($type)->getName(), [ + 'weight' => $source_field_weight, + ]); } } diff --git a/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php b/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php index 19dde8b3ac30a76d4c8f8f37701988064e099187..e2389f5301d415c5f91a6f37bec236c205addf4d 100644 --- a/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php +++ b/core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php @@ -22,18 +22,22 @@ class TestDifferentDisplays extends Test { * {@inheritdoc} */ public function prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayInterface $display) { - $display->setComponent($this->getSourceFieldDefinition($type)->getName(), [ - 'type' => 'entity_reference_entity_id', - ]); + parent::prepareViewDisplay($type, $display); + $source_name = $this->getSourceFieldDefinition($type)->getName(); + $source_component = $display->getComponent($source_name) ?: []; + $source_component['type'] = 'entity_reference_entity_id'; + $display->setComponent($source_name, $source_component); } /** * {@inheritdoc} */ public function prepareFormDisplay(MediaTypeInterface $type, EntityFormDisplayInterface $display) { - $display->setComponent($this->getSourceFieldDefinition($type)->getName(), [ - 'type' => 'entity_reference_autocomplete_tags', - ]); + parent::prepareFormDisplay($type, $display); + $source_name = $this->getSourceFieldDefinition($type)->getName(); + $source_component = $display->getComponent($source_name) ?: []; + $source_component['type'] = 'entity_reference_autocomplete_tags'; + $display->setComponent($source_name, $source_component); } /** diff --git a/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php b/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php index 4f491ccb4a07aabb61cb1bc0710a7177a9cd57f3..61fe2a9c55e169cb838095be09485d49ddd833e5 100644 --- a/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\media\FunctionalJavascript; +use Drupal\Component\Utility\Html; + /** * Tests the media type creation. * @@ -54,6 +56,27 @@ public function testMediaTypeCreationFormWithDefaultField() { $assert_session->fieldDisabled('Media source'); $assert_session->pageTextContains('The media source cannot be changed after the media type is created.'); + // Open up the media add form and verify that the source field is right + // after the name, and before the vertical tabs. + $this->drupalGet("/media/add/$mediaTypeMachineName"); + + // Get the form element, and its HTML representation. + $form_selector = '#media-' . Html::cleanCssIdentifier($mediaTypeMachineName) . '-add-form'; + $form = $assert_session->elementExists('css', $form_selector); + $form_html = $form->getOuterHtml(); + + // The name field should come before the source field, which should itself + // come before the vertical tabs. + $name_field = $assert_session->fieldExists('Name', $form)->getOuterHtml(); + $test_source_field = $assert_session->fieldExists('Test source', $form)->getOuterHtml(); + $vertical_tabs = $assert_session->elementExists('css', '.vertical-tabs', $form)->getOuterHtml(); + $date_field = $assert_session->fieldExists('Date', $form)->getOuterHtml(); + $published_checkbox = $assert_session->fieldExists('Published', $form)->getOuterHtml(); + $this->assertTrue(strpos($form_html, $test_source_field) > strpos($form_html, $name_field)); + $this->assertTrue(strpos($form_html, $vertical_tabs) > strpos($form_html, $test_source_field)); + // The "Published" checkbox should be the last element. + $this->assertTrue(strpos($form_html, $published_checkbox) > strpos($form_html, $date_field)); + // Check that a new type with the same machine name cannot be created. $this->drupalGet('admin/structure/media/add'); $page->fillField('label', $label); diff --git a/core/profiles/standard/config/optional/core.entity_form_display.media.audio.default.yml b/core/profiles/standard/config/optional/core.entity_form_display.media.audio.default.yml index 8eebf67fb49ffcc82d98c240c8449ed42a6f5332..b3f5f6497f6d32e253966352c84a4949cea84236 100644 --- a/core/profiles/standard/config/optional/core.entity_form_display.media.audio.default.yml +++ b/core/profiles/standard/config/optional/core.entity_form_display.media.audio.default.yml @@ -19,7 +19,7 @@ content: settings: { } third_party_settings: { } field_media_audio_file: - weight: 1 + weight: 0 settings: progress_indicator: throbber third_party_settings: { } @@ -27,7 +27,7 @@ content: region: content name: type: string_textfield - weight: 0 + weight: -5 region: content settings: size: 60 diff --git a/core/profiles/standard/config/optional/core.entity_form_display.media.file.default.yml b/core/profiles/standard/config/optional/core.entity_form_display.media.file.default.yml index 50d57bc22a1a8c4d12d679929eb5c3739d5c54e6..8b4ebe9f3b10e50845b923b62b000be11dc158d7 100644 --- a/core/profiles/standard/config/optional/core.entity_form_display.media.file.default.yml +++ b/core/profiles/standard/config/optional/core.entity_form_display.media.file.default.yml @@ -22,7 +22,7 @@ content: progress_indicator: throbber third_party_settings: { } type: file_generic - weight: 26 + weight: 0 region: content name: type: string_textfield diff --git a/core/profiles/standard/config/optional/core.entity_form_display.media.image.default.yml b/core/profiles/standard/config/optional/core.entity_form_display.media.image.default.yml index 6f2323b77806f5b80e6877236c78882813c1545c..4488b02eebc6a09c845440747ca1741a2c8f257d 100644 --- a/core/profiles/standard/config/optional/core.entity_form_display.media.image.default.yml +++ b/core/profiles/standard/config/optional/core.entity_form_display.media.image.default.yml @@ -24,7 +24,7 @@ content: preview_image_style: thumbnail third_party_settings: { } type: image_image - weight: 26 + weight: 0 region: content name: type: string_textfield diff --git a/core/profiles/standard/config/optional/core.entity_form_display.media.video.default.yml b/core/profiles/standard/config/optional/core.entity_form_display.media.video.default.yml index d8c948133ff456d1ecf91bb0d07deea72ee91923..658648fd183c7eb47add596e4e34dabd1726b1ec 100644 --- a/core/profiles/standard/config/optional/core.entity_form_display.media.video.default.yml +++ b/core/profiles/standard/config/optional/core.entity_form_display.media.video.default.yml @@ -19,7 +19,7 @@ content: settings: { } third_party_settings: { } field_media_video_file: - weight: 1 + weight: 0 settings: progress_indicator: throbber third_party_settings: { } @@ -27,7 +27,7 @@ content: region: content name: type: string_textfield - weight: 0 + weight: -5 region: content settings: size: 60