diff --git a/core/modules/media/templates/media.html.twig b/core/modules/media/templates/media.html.twig index 4173199..28c0a83 100644 --- a/core/modules/media/templates/media.html.twig +++ b/core/modules/media/templates/media.html.twig @@ -32,17 +32,5 @@ */ #} - {# - In the 'full' view mode the entity label is assumed to be displayed as the - page title, so we do not display it here. - #} - {{ title_prefix }} - {% if label and view_mode != 'full' %} - - {{ label }} - - {% endif %} - {{ title_suffix }} - {{ content }} diff --git a/core/modules/media/tests/src/Functional/MediaDisplayTest.php b/core/modules/media/tests/src/Functional/MediaDisplayTest.php new file mode 100644 index 0000000..1242ceb --- /dev/null +++ b/core/modules/media/tests/src/Functional/MediaDisplayTest.php @@ -0,0 +1,88 @@ +assertSession(); + $page = $this->getSession()->getPage(); + + $media_type = $this->createMediaType(); + + // Create a media item. + $media = Media::create([ + 'bundle' => $media_type->id(), + 'name' => 'Fantastic!', + ]); + $media->save(); + + $this->drupalGet('media/' . $media->id()); + // Verify the "name" field is really not present. + $assert_session->elementNotExists('css', '.field--name-name'); + + // Enable the field on the display and verify it becomes visible on the UI. + $this->drupalGet("/admin/structure/media/manage/{$media_type->id()}/display"); + $page->selectFieldOption('fields[name][region]', 'content'); + $assert_session->waitForElementVisible('css', '#edit-fields-name-settings-edit'); + $page->pressButton('Save'); + $this->drupalGet('media/' . $media->id()); + $assert_session->elementExists('css', '.field--name-name'); + $name_field = $page->find('css', '.field--name-name .field__item'); + $this->assertEquals($media->label(), $name_field->getText()); + + // 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'); + $page->fillField('name[0][value]', 'Image media 1'); + $page->attachFileToField('files[field_media_image_0]', \Drupal::root() . '/core/modules/media/tests/fixtures/example_1.jpeg'); + $result = $assert_session->waitForButton('Remove'); + $this->assertNotEmpty($result); + $page->fillField('field_media_image[0][alt]', 'Image Alt Text 1'); + $page->pressButton('Save'); + + // Here we expect to see only the image, nothing else. + // 1) Assert only one element in the content region. + $this->assertEquals(1, count($page->findAll('css', 'article.media--type-image > div'))); + // 2) Assert the image is present, with "medium" image style. + $assert_session->elementExists('css', 'article.media--type-image img.image-style-medium'); + + $test_filename = $this->randomMachineName() . '.txt'; + $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); + $page->pressButton('Save'); + + // Here we expect to see only the linked filename. + // 1) Assert only one element in the content region. + $this->assertEquals(1, count($page->findAll('css', 'article.media--type-file > div'))); + // 2) Assert the file link is present, and its text matches the filename. + $assert_session->elementExists('css', 'article.media--type-file .field--name-field-media-file a'); + $link = $page->find('css', 'article.media--type-file .field--name-field-media-file a'); + $this->assertEquals($test_filename, $link->getText()); + + } + +} diff --git a/core/profiles/standard/config/optional/core.entity_view_display.media.file.default.yml b/core/profiles/standard/config/optional/core.entity_view_display.media.file.default.yml index f42bab7..72b0bdc 100644 --- a/core/profiles/standard/config/optional/core.entity_view_display.media.file.default.yml +++ b/core/profiles/standard/config/optional/core.entity_view_display.media.file.default.yml @@ -18,15 +18,8 @@ content: type: file_default weight: 1 region: content - name: - label: hidden - type: string - weight: 0 - region: content - settings: - link_to_entity: false - third_party_settings: { } hidden: created: true thumbnail: true uid: true + name: true