From 232cd66de70cb6d3d99deef51a9730c2c14f74bc Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Thu, 23 Jul 2020 13:52:43 +1000
Subject: [PATCH] Issue #3122051 by phenaproxima, andrewmacpherson, Kristen
 Pol: Name field is always shown on media library form display when adding a
 new remote video media type

(cherry picked from commit bbb2de82426fbe48d1baa9deb421beae68d0814d)
---
 core/modules/media_library/media_library.module  |  3 +--
 .../Functional/MediaLibraryDisplayModeTest.php   | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/core/modules/media_library/media_library.module b/core/modules/media_library/media_library.module
index 19ef3c2131d7..5312b8e96dbe 100644
--- a/core/modules/media_library/media_library.module
+++ b/core/modules/media_library/media_library.module
@@ -402,8 +402,7 @@ function _media_library_configure_form_display(MediaTypeInterface $type) {
     $display->removeComponent($name);
   }
   // Expose the name field when it is not mapped.
-  $field_map = $type->getFieldMap();
-  if (empty($field_map['name'])) {
+  if (!in_array('name', $type->getFieldMap(), TRUE)) {
     $display->setComponent('name', [
       'type' => 'string_textfield',
       'settings' => [
diff --git a/core/modules/media_library/tests/src/Functional/MediaLibraryDisplayModeTest.php b/core/modules/media_library/tests/src/Functional/MediaLibraryDisplayModeTest.php
index 47023f88d110..2d4c056f345e 100644
--- a/core/modules/media_library/tests/src/Functional/MediaLibraryDisplayModeTest.php
+++ b/core/modules/media_library/tests/src/Functional/MediaLibraryDisplayModeTest.php
@@ -162,6 +162,22 @@ public function testDisplayModes() {
     $this->assertFormDisplay($type_eight_id, FALSE, TRUE);
     $this->assertViewDisplay($type_eight_id, 'medium');
 
+    // Create an oEmbed media type with a mapped name field in the UI.
+    $type_id = 'pinto_bean';
+    $edit = [
+      'label' => $type_id,
+      'id' => $type_id,
+      'source' => 'oembed:video',
+    ];
+    $this->drupalPostForm('admin/structure/media/add', $edit, 'Save');
+    $edit = [
+      'field_map[title]' => 'name',
+    ];
+    $this->drupalPostForm(NULL, $edit, t('Save'));
+    $this->assertSession()->pageTextContains("Media Library form and view displays have been created for the $type_id media type.");
+    $this->assertFormDisplay($type_id, FALSE, FALSE);
+    $this->assertViewDisplay($type_id, 'medium');
+
     // Delete a form and view display.
     EntityFormDisplay::load('media.type_one.media_library')->delete();
     EntityViewDisplay::load('media.type_one.media_library')->delete();
-- 
GitLab