From fc0e9e07f613f5898b1cc9cf3260a1f9e87d4d11 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sat, 9 Nov 2019 16:31:32 -0800 Subject: [PATCH] Add object-fit=contain to amp-youtube placeholder image --- .../embeds/class-amp-youtube-embed-handler.php | 5 +++-- .../php/test-class-amp-youtube-embed-handler.php | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/includes/embeds/class-amp-youtube-embed-handler.php b/includes/embeds/class-amp-youtube-embed-handler.php index 31cbe179e4a..02506d41ccb 100644 --- a/includes/embeds/class-amp-youtube-embed-handler.php +++ b/includes/embeds/class-amp-youtube-embed-handler.php @@ -107,8 +107,9 @@ private function parse_props( $html, $url, $video_id ) { } $img_attributes = [ - 'src' => esc_url_raw( sprintf( 'https://i.ytimg.com/vi/%s/hqdefault.jpg', $video_id ) ), - 'data-amp-layout' => 'fill', + 'src' => esc_url_raw( sprintf( 'https://i.ytimg.com/vi/%s/hqdefault.jpg', $video_id ) ), + 'layout' => 'fill', + 'object-fit' => 'cover', ]; if ( ! empty( $props['title'] ) ) { $img_attributes['alt'] = $props['title']; diff --git a/tests/php/test-class-amp-youtube-embed-handler.php b/tests/php/test-class-amp-youtube-embed-handler.php index 43ce3d72f25..3840ca22b82 100644 --- a/tests/php/test-class-amp-youtube-embed-handler.php +++ b/tests/php/test-class-amp-youtube-embed-handler.php @@ -133,20 +133,20 @@ public function get_conversion_data() { 'url_simple' => [ 'https://www.youtube.com/watch?v=kfVsfOSbJY0' . PHP_EOL, - '

Rebecca Black - Friday

' . PHP_EOL, - '

' . PHP_EOL, + '

Rebecca Black - Friday

' . PHP_EOL, + '

' . PHP_EOL, ], 'url_short' => [ 'https://youtu.be/kfVsfOSbJY0' . PHP_EOL, - '

Rebecca Black - Friday

' . PHP_EOL, - '

' . PHP_EOL, + '

Rebecca Black - Friday

' . PHP_EOL, + '

' . PHP_EOL, ], 'url_with_querystring' => [ 'http://www.youtube.com/watch?v=kfVsfOSbJY0&hl=en&fs=1&w=425&h=349' . PHP_EOL, - '

Rebecca Black - Friday

' . PHP_EOL, - '

' . PHP_EOL, + '

Rebecca Black - Friday

' . PHP_EOL, + '

' . PHP_EOL, ], // Several reports of invalid URLs that have multiple `?` in the URL. @@ -162,8 +162,8 @@ public function get_conversion_data() { 'embed_url' => [ 'https://www.youtube.com/embed/kfVsfOSbJY0' . PHP_EOL, - '

Rebecca Black - Friday

' . PHP_EOL, - '

' . PHP_EOL, + '

Rebecca Black - Friday

' . PHP_EOL, + '

' . PHP_EOL, ], ]; }