summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2018-01-08 19:26:36 (GMT)
committerxjm2018-01-08 19:27:02 (GMT)
commit27ff71aacfe8978e2b02cef772f821369f957271 (patch)
treec700ecc505d6619daeefacdce57a5c5a323ab8f6
parent60a2dc0be41d2bdc267523c42cf3ad3c77e664cb (diff)
Issue #2934162 by marcoscano, phenaproxima, chr.fritsch, robpowell, Berdir, xjm, effulgentsia: Provide better defaults to media form displays
-rw-r--r--core/modules/media/src/MediaSourceBase.php7
-rw-r--r--core/modules/media/tests/modules/media_test_source/src/Plugin/media/Source/TestDifferentDisplays.php16
-rw-r--r--core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php23
-rw-r--r--core/profiles/standard/config/optional/core.entity_form_display.media.audio.default.yml4
-rw-r--r--core/profiles/standard/config/optional/core.entity_form_display.media.file.default.yml2
-rw-r--r--core/profiles/standard/config/optional/core.entity_form_display.media.image.default.yml2
-rw-r--r--core/profiles/standard/config/optional/core.entity_form_display.media.video.default.yml4
7 files changed, 45 insertions, 13 deletions
diff --git a/core/modules/media/src/MediaSourceBase.php b/core/modules/media/src/MediaSourceBase.php
index 8328899..1edc858 100644
--- a/core/modules/media/src/MediaSourceBase.php
+++ b/core/modules/media/src/MediaSourceBase.php
@@ -344,7 +344,12 @@ abstract class MediaSourceBase extends PluginBase implements MediaSourceInterfac
* {@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 19dde8b..e2389f5 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 4f491cc..61fe2a9 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 @@ class MediaTypeCreationTest extends MediaJavascriptTestBase {
$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 8eebf67..b3f5f64 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 50d57bc..8b4ebe9 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 6f2323b..4488b02 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 d8c9481..658648f 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