diff --git a/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php b/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php index 65d601eb6373..c08c84f40ab2 100644 --- a/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php +++ b/core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php @@ -229,6 +229,13 @@ class OEmbedFormatter extends FormatterBase implements ContainerFactoryPluginInt ], ]; + // An empty title attribute will disable title inheritance, so only + // add it if the resource has a title. + $title = $resource->getTitle(); + if ($title) { + $element[$delta]['#attributes']['title'] = $title; + } + CacheableMetadata::createFromObject($resource) ->addCacheTags($this->config->getCacheTags()) ->applyTo($element[$delta]); diff --git a/core/modules/media/tests/fixtures/oembed/video_vimeo-no-title.html b/core/modules/media/tests/fixtures/oembed/video_vimeo-no-title.html new file mode 100644 index 000000000000..210151fa30c1 --- /dev/null +++ b/core/modules/media/tests/fixtures/oembed/video_vimeo-no-title.html @@ -0,0 +1,8 @@ + + +
+ + + + diff --git a/core/modules/media/tests/fixtures/oembed/video_vimeo-no-title.json b/core/modules/media/tests/fixtures/oembed/video_vimeo-no-title.json new file mode 100644 index 000000000000..a4e905685d28 --- /dev/null +++ b/core/modules/media/tests/fixtures/oembed/video_vimeo-no-title.json @@ -0,0 +1,16 @@ +{ + "type": "video", + "version": "1.0", + "provider_name": "Vimeo", + "provider_url": "https:\/\/vimeo.com\/", + "title": "", + "author_name": "Tendenci - The Open Source AMS", + "author_url": "https:\/\/vimeo.com\/schipul", + "html": "", + "width": 480, + "height": 360, + "description": "Special thanks to Tendenci, formerly Schipul for sponsoring this video with training, equipment and time. The open source way. All creative however was self directed by the individuals - A. Hughes (www.schipul.com\/ahughes) featuring QCait (www.schipul.com\/qcait) - Hands On Drupal\n\nDrupal is a free software package that allows an individual or a community of users to easily publish, manage and organize a wide variety of content on a website.\n\nNeed a little Drupal help or just want to geek out with us? Visit our www.schipul.com\/drupal for more info - we'd love to connect!\n\nGo here for Drupal Common Terms and Suggested Modules : http:\/\/schipul.com\/en\/helpfiles\/v\/229", + "thumbnail_url": "internal:\/core\/misc\/druplicon.png", + "thumbnail_width": 295, + "thumbnail_height": 221 +} diff --git a/core/modules/media/tests/src/Functional/FieldFormatter/OEmbedFormatterTest.php b/core/modules/media/tests/src/Functional/FieldFormatter/OEmbedFormatterTest.php index eecc9cde5fb2..2a0a0959586d 100644 --- a/core/modules/media/tests/src/Functional/FieldFormatter/OEmbedFormatterTest.php +++ b/core/modules/media/tests/src/Functional/FieldFormatter/OEmbedFormatterTest.php @@ -58,20 +58,35 @@ class OEmbedFormatterTest extends MediaFunctionalTestBase { [ 'iframe' => [ 'src' => '/media/oembed?url=https%3A//vimeo.com/7073899', - 'width' => 480, - 'height' => 360, + 'width' => '480', + 'height' => '360', + 'title' => 'Drupal Rap Video - Schipulcon09', ], ], ], 'Vimeo video, resized' => [ 'https://vimeo.com/7073899', 'video_vimeo.json?maxwidth=100&maxheight=100', - ['max_width' => 100, 'max_height' => 100], + ['max_width' => '100', 'max_height' => '100'], [ 'iframe' => [ 'src' => '/media/oembed?url=https%3A//vimeo.com/7073899', - 'width' => 100, - 'height' => 100, + 'width' => '100', + 'height' => '100', + 'title' => 'Drupal Rap Video - Schipulcon09', + ], + ], + ], + 'Vimeo video, no title' => [ + 'https://vimeo.com/7073899', + 'video_vimeo-no-title.json', + [], + [ + 'iframe' => [ + 'src' => '/media/oembed?url=https%3A//vimeo.com/7073899', + 'width' => '480', + 'height' => '360', + 'title' => NULL, ], ], ], @@ -82,8 +97,8 @@ class OEmbedFormatterTest extends MediaFunctionalTestBase { [ 'iframe' => [ 'src' => '/media/oembed?url=https%3A//twitter.com/drupaldevdays/status/935643039741202432', - 'width' => 550, - 'height' => 360, + 'width' => '550', + 'height' => '360', ], ], ], @@ -94,8 +109,8 @@ class OEmbedFormatterTest extends MediaFunctionalTestBase { [ 'img' => [ 'src' => '/core/misc/druplicon.png', - 'width' => 88, - 'height' => 100, + 'width' => '88', + 'height' => '100', ], ], ], @@ -171,8 +186,14 @@ class OEmbedFormatterTest extends MediaFunctionalTestBase { $assert = $this->assertSession(); $assert->statusCodeEquals(200); foreach ($selectors as $selector => $attributes) { + $element = $assert->elementExists('css', $selector); foreach ($attributes as $attribute => $value) { - $assert->elementAttributeContains('css', $selector, $attribute, $value); + if (isset($value)) { + $this->assertContains($value, $element->getAttribute($attribute)); + } + else { + $this->assertFalse($element->hasAttribute($attribute)); + } } } }