Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EWPP-2711: Set remote video iframe ratio 1-1 and auto height. #1201

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,8 @@ function oe_theme_preprocess_paragraph__oe_text_feature_media(array &$variables)
// If it is an OEmbed resource, render it and pass it as embeddable data
// only if it is of type video or html.
if ($source instanceof OEmbed) {
// Use 1-1 ratio for OEmbed.
$variables['ratio'] = '1:1';
$oembed_type = $source->getMetadata($media, 'type');
if (in_array($oembed_type, ['video', 'html'])) {
$variables['video'] = $media->{$source_field->getName()}->view($display_options);
Expand Down
4 changes: 4 additions & 0 deletions sass/components/_media_iframe.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
}
}
}

.ecl-media-container iframe {
height: auto!important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
{% for item in items %}
{% include '@ecl-twig/media-container' with {
'embedded_media': item.content,
'ratio': '1-1',
} %}
{% endfor %}
24 changes: 18 additions & 6 deletions tests/src/Functional/ContentNewsRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Drupal\Tests\oe_theme\Functional;

use Drupal\Core\Url;
use Drupal\Tests\oe_theme\PatternAssertions\FieldListAssert;
use Drupal\Tests\oe_theme\PatternAssertions\PatternPageHeaderAssert;
use Drupal\user\Entity\Role;
Expand Down Expand Up @@ -202,14 +203,25 @@ public function testNewsRendering(): void {
// Assert Featured media field.
$this->assertSession()->elementNotExists('css', 'article[role=article] article.ecl-u-type-paragraph.ecl-u-mb-l');

$media = $this->createMediaImage('news_featured_media');
// Create a remote video and add it to the node.
$media = $this->getStorage('media')->create([
'bundle' => 'remote_video',
'oe_media_oembed_video' => [
'value' => 'https://www.youtube.com/watch?v=1-g73ty9v04',
],
]);
$media->save();
$node->set('oe_news_featured_media', [$media])->save();
$this->drupalGet($node->toUrl());

$picture = $this->assertSession()->elementExists('css', 'article[role=article] article.ecl-u-type-paragraph.ecl-u-mb-l picture');
$image = $this->assertSession()->elementExists('css', 'img.ecl-u-width-100.ecl-u-height-auto', $picture);
$this->assertStringContainsString('files/styles/oe_theme_medium_no_crop/public/placeholder_news_featured_media.png', $image->getAttribute('src'));
$this->assertEquals('Alternative text news_featured_media', $image->getAttribute('alt'));
$media_container = $this->assertSession()->elementExists('css', 'article.ecl-u-type-paragraph.ecl-u-mb-l figure.ecl-media-container');
// Assert the media container uses 1-1 ratio.
$video = $this->assertSession()->elementExists('css', 'div.ecl-media-container__media.ecl-media-container__media--ratio-1-1 iframe', $media_container);
$partial_video_url = Url::fromRoute('media.oembed_iframe', [], [
'query' => [
'url' => 'https://www.youtube.com/watch?v=1-g73ty9v04',
],
])->toString();
$this->assertStringContainsString($partial_video_url, $video->getAttribute('src'));

// Unpublish the media and assert it is not rendered anymore.
$media->set('status', 0);
Expand Down
5 changes: 3 additions & 2 deletions tests/src/Kernel/Paragraphs/MediaParagraphsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ public function testTextWithMedia(): void {
$media_container = $crawler->filter('div.ecl-media-container__media');
$existing_classes = $media_container->attr('class');
$existing_classes = explode(' ', $existing_classes);
$this->assertContains('ecl-media-container__media--ratio-16-9', $existing_classes);
// Assert remote videos use 1-1 ratio.
$this->assertContains('ecl-media-container__media--ratio-1-1', $existing_classes);
$video_iframe = $media_container->filter('iframe');
$partial_iframe_url = Url::fromRoute('media.oembed_iframe', [], [
'query' => [
Expand All @@ -273,7 +274,7 @@ public function testTextWithMedia(): void {
$paragraph->set('field_oe_media', ['target_id' => $media->id()]);
$paragraph->save();

// Assert AV video is rendered properly.
// Assert AV Portal video is rendered properly.
$html = $this->renderParagraph($paragraph);
$expected_values = [
'title' => NULL,
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/fixtures/rendering.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2847,7 +2847,7 @@
'figure.ecl-media-container.ecl-featured-item__media_container.ecl-featured-item__media_container': 0
'div.ecl-featured-item__item.ecl': 0
'img.ecl-media-container__media[src="http://via.placeholder.com/150x150"]': 0
'div.ecl-media-container__media--ratio-16-9 iframe': 0
'div.ecl-media-container__media--ratio-1-1 iframe': 0
'figcaption.ecl-media-container__caption': 0
'a.ecl-link': 0
equals:
Expand Down