Commit 4f658faf authored by alexpott's avatar alexpott

Issue #2882473 by seanB, chr.fritsch, marcoscano, pk188, xjm, phenaproxima,...

Issue #2882473 by seanB, chr.fritsch, marcoscano, pk188, xjm, phenaproxima, Wim Leers, sreher, slashrsm, Berdir: Hide the media name basefield from the entity form by default
parent 2b511ec3
<!DOCTYPE html>
<html lang="nl">
<head>
<link rel="alternate" href="video_youtube.json"
type="application/json+oembed" title="Everyday I'm Drupalin' Drupal Rap (Rick Ross - Hustlin)">
</head>
<body></body>
</html>
{
"type": "video",
"version": "1.0",
"provider_name": "YouTube",
"provider_url": "https:\/\/www.youtube.com\/",
"title": "Everyday I'm Drupalin' Drupal Rap (Rick Ross - Hustlin)",
"author_name": "Mirakolous",
"author_url": "https:\/\/www.youtube.com\/user\/Mirakolous",
"html": "<h1>By the power of Greyskull, YouTube works!</h1>",
"width": 480,
"height": 270,
"thumbnail_url": "internal:\/core\/misc\/druplicon.png",
"thumbnail_width": 480,
"thumbnail_height": 360
}
......@@ -68,9 +68,8 @@ public function testMediaDisplay() {
// In the standard profile, there are some pre-cooked types. Make sure the
// elements configured on their displays are the expected ones.
$this->drupalGet('media/add/image');
$image_media_name = 'Fantastic image asset!';
$page->fillField('name[0][value]', $image_media_name);
$page->attachFileToField('files[field_media_image_0]', $this->root . '/core/modules/media/tests/fixtures/example_1.jpeg');
$image_media_name = 'example_1.jpeg';
$page->attachFileToField('files[field_media_image_0]', $this->root . '/core/modules/media/tests/fixtures/' . $image_media_name);
$result = $assert_session->waitForButton('Remove');
$this->assertNotEmpty($result);
$page->fillField('field_media_image[0][alt]', 'Image Alt Text 1');
......@@ -86,6 +85,8 @@ public function testMediaDisplay() {
// Go to the media entity view.
$this->drupalGet('/media/' . $image_media_id);
// Check if the default media name is generated as expected.
$assert_session->elementTextContains('css', 'h1', $image_media_name);
// Here we expect to see only the image, nothing else.
// Assert only one element in the content region.
$this->assertSame(1, count($page->findAll('css', '.media--type-image > div')));
......@@ -101,7 +102,6 @@ public function testMediaDisplay() {
$test_filepath = 'public://' . $test_filename;
file_put_contents($test_filepath, $this->randomMachineName());
$this->drupalGet("media/add/file");
$page->fillField('name[0][value]', 'File media 1');
$page->attachFileToField("files[field_media_file_0]", \Drupal::service('file_system')->realpath($test_filepath));
$result = $assert_session->waitForButton('Remove');
$this->assertNotEmpty($result);
......@@ -110,6 +110,8 @@ public function testMediaDisplay() {
// Go to the media entity view.
$this->drupalGet($this->assertLinkToCreatedMedia());
// Check if the default media name is generated as expected.
$assert_session->elementTextContains('css', 'h1', $test_filename);
// Here we expect to see only the linked filename.
// Assert only one element in the content region.
$this->assertSame(1, count($page->findAll('css', 'article.media--type-file > div')));
......
......@@ -9,18 +9,11 @@ id: media.audio.media_library
targetEntityType: media
bundle: audio
mode: media_library
content:
name:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
content: { }
hidden:
created: true
field_media_audio_file: true
name: true
path: true
status: true
uid: true
......@@ -9,18 +9,11 @@ id: media.file.media_library
targetEntityType: media
bundle: file
mode: media_library
content:
name:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
content: { }
hidden:
created: true
field_media_file: true
name: true
path: true
status: true
uid: true
......@@ -21,16 +21,9 @@ content:
progress_indicator: throbber
preview_image_style: thumbnail
third_party_settings: { }
name:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
hidden:
created: true
name: true
path: true
status: true
uid: true
......@@ -9,18 +9,11 @@ id: media.video.media_library
targetEntityType: media
bundle: video
mode: media_library
content:
name:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
content: { }
hidden:
created: true
field_media_video_file: true
name: true
path: true
status: true
uid: true
......@@ -176,8 +176,19 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#uri' => $thumbnail_uri,
];
}
EntityFormDisplay::collectRenderDisplay($media, 'media_library')
->buildForm($media, $element['fields'], $form_state);
$form_display = EntityFormDisplay::collectRenderDisplay($media, 'media_library');
// When the name is not added to the form as a editable field, output
// the name as a fixed element to confirm the right file was uploaded.
if (!$form_display->getComponent('name')) {
$element['fields']['name'] = [
'#type' => 'item',
'#title' => $this->t('Name'),
'#markup' => $media->getName(),
];
}
$form_display->buildForm($media, $element['fields'], $form_state);
// We hide certain elements in the image widget with CSS.
if (isset($element['fields'][$source_field])) {
$element['fields'][$source_field]['#attributes']['class'][] = 'media-library-upload__source-field';
......
......@@ -25,14 +25,6 @@ content:
third_party_settings: { }
type: file_generic
region: content
name:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 30
......@@ -57,3 +49,4 @@ content:
third_party_settings: { }
hidden:
moderation_state: true
name: true
......@@ -25,14 +25,6 @@ content:
type: file_generic
weight: 0
region: content
name:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 4
......@@ -57,3 +49,4 @@ content:
third_party_settings: { }
hidden:
moderation_state: true
name: true
......@@ -27,14 +27,6 @@ content:
type: image_image
weight: 0
region: content
name:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 4
......@@ -59,3 +51,4 @@ content:
third_party_settings: { }
hidden:
moderation_state: true
name: true
......@@ -25,14 +25,6 @@ content:
third_party_settings: { }
type: file_generic
region: content
name:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 30
......@@ -57,3 +49,4 @@ content:
third_party_settings: { }
hidden:
moderation_state: true
name: true
......@@ -9,4 +9,5 @@ queue_thumbnail_downloads: false
new_revision: true
source_configuration:
source_field: field_media_audio_file
field_map: { }
field_map:
name: name
......@@ -9,4 +9,5 @@ queue_thumbnail_downloads: false
new_revision: true
source_configuration:
source_field: field_media_file
field_map: { }
field_map:
name: name
......@@ -9,4 +9,5 @@ queue_thumbnail_downloads: false
new_revision: true
source_configuration:
source_field: field_media_image
field_map: { }
field_map:
name: name
......@@ -13,4 +13,5 @@ source_configuration:
- YouTube
- Vimeo
source_field: field_media_oembed_video
field_map: { }
field_map:
title: name
......@@ -9,4 +9,5 @@ queue_thumbnail_downloads: false
new_revision: true
source_configuration:
source_field: field_media_video_file
field_map: { }
field_map:
name: name
......@@ -25,14 +25,6 @@ content:
third_party_settings: { }
type: file_generic
region: content
name:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 30
......@@ -55,4 +47,5 @@ content:
placeholder: ''
region: content
third_party_settings: { }
hidden: { }
hidden:
name: true
......@@ -24,14 +24,6 @@ content:
type: file_generic
weight: 0
region: content
name:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
status:
type: boolean_checkbox
settings:
......@@ -48,4 +40,5 @@ content:
placeholder: ''
region: content
third_party_settings: { }
hidden: { }
hidden:
name: true
......@@ -26,14 +26,6 @@ content:
type: image_image
weight: 0
region: content
name:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
status:
type: boolean_checkbox
settings:
......@@ -50,4 +42,5 @@ content:
placeholder: ''
region: content
third_party_settings: { }
hidden: { }
hidden:
name: true
......@@ -25,14 +25,6 @@ content:
third_party_settings: { }
type: file_generic
region: content
name:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 30
......@@ -55,4 +47,5 @@ content:
placeholder: ''
region: content
third_party_settings: { }
hidden: { }
hidden:
name: true
......@@ -9,4 +9,5 @@ queue_thumbnail_downloads: false
new_revision: true
source_configuration:
source_field: field_media_audio_file
field_map: { }
field_map:
name: name
......@@ -9,4 +9,5 @@ queue_thumbnail_downloads: false
new_revision: true
source_configuration:
source_field: field_media_file
field_map: { }
field_map:
name: name
......@@ -9,4 +9,5 @@ queue_thumbnail_downloads: false
new_revision: true
source_configuration:
source_field: field_media_image
field_map: { }
field_map:
name: name
......@@ -13,4 +13,5 @@ source_configuration:
- YouTube
- Vimeo
source_field: field_media_oembed_video
field_map: { }
field_map:
title: name
......@@ -9,4 +9,5 @@ queue_thumbnail_downloads: false
new_revision: true
source_configuration:
source_field: field_media_video_file
field_map: { }
field_map:
name: name
......@@ -242,18 +242,15 @@ public function testStandard() {
$form = $assert_session->elementExists('css', $form_selector);
$form_html = $form->getOuterHtml();
// The name field (if it exists) should come before the source field,
// which should itself come before the vertical tabs.
// The name field should be hidden.
$assert_session->fieldNotExists('Name', $form);
// The source field should be shown before the vertical tabs.
$test_source_field = $assert_session->fieldExists($media_type->getSource()->getSourceFieldDefinition($media_type)->getLabel(), $form)->getOuterHtml();
$vertical_tabs = $assert_session->elementExists('css', '.form-type-vertical-tabs', $form)->getOuterHtml();
$date_field = $assert_session->fieldExists('Date', $form)->getOuterHtml();
$published_checkbox = $assert_session->fieldExists('Published', $form)->getOuterHtml();
if ($page->findField('Name')) {
$name_field = $assert_session->fieldExists('Name', $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.
$date_field = $assert_session->fieldExists('Date', $form)->getOuterHtml();
$published_checkbox = $assert_session->fieldExists('Published', $form)->getOuterHtml();
$this->assertTrue(strpos($form_html, $published_checkbox) > strpos($form_html, $date_field));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment