Skip to content

Commit

Permalink
EWPP-3048: Do not apply custom ratio class on iframes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nagyad committed Jan 30, 2023
1 parent e122f78 commit 54fd837
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 10 deletions.
3 changes: 1 addition & 2 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -1668,8 +1668,7 @@ function oe_theme_preprocess_field__media__oe_media_iframe__video_iframe__oe_the
* Prepared ratio to be used in templates.
*/
function _oe_theme_get_oe_media_iframe_ratio(MediaInterface $media): string {
$ratio = $media->get('oe_media_iframe_ratio')->value ?? 'custom';
return str_replace('_', '-', $ratio);
return $media->get('oe_media_iframe_ratio')->isEmpty() ? '' : str_replace('_', '-', $media->get('oe_media_iframe_ratio')->value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
{% include '@ecl-twig/media-container' with {
'embedded_media': item.content,
'ratio': ratio,
'extra_classes': (ratio == 'custom') ? 'ecl-media-container--custom-ratio' : '',
} %}
{% endfor %}
4 changes: 0 additions & 4 deletions templates/paragraphs/paragraph--oe-iframe-media.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
{% set extra_classes = ['ecl-media-container--fullwidth'] %}
{% endif %}

{% if ratio == 'custom' %}
{% set extra_classes = extra_classes|merge(['ecl-media-container--custom-ratio']) %}
{% endif %}

{% if not paragraph.field_oe_title.isEmpty() %}
<h2 class="ecl-u-type-heading-2">{{ content.field_oe_title }}</h2>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Kernel/MediaRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function testIframeMedia(): void {
$build = $this->mediaViewBuilder->view($media, 'oe_theme_main_content');
$html = $this->renderRoot($build);
$crawler = new Crawler($html);
$iframe = $crawler->filter('.ecl-media-container .ecl-media-container__media--ratio-custom iframe');
$iframe = $crawler->filter('.ecl-media-container iframe');
$this->assertEquals('http://example.com/iframe_media', $iframe->attr('src'));

// Assert iframe media with aspect ratio 3:2.
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Kernel/Paragraphs/MediaParagraphsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -891,15 +891,15 @@ public function testIframe(): void {
$this->container->get('entity_type.manager')->getAccessControlHandler('media')->resetCache();
$html = $this->renderParagraph($paragraph);
$crawler = new Crawler($html);
$iframe = $crawler->filter('figure.ecl-media-container.ecl-media-container--custom-ratio div.ecl-media-container__media.ecl-media-container__media--ratio-custom iframe');
$iframe = $crawler->filter('figure.ecl-media-container div.ecl-media-container__media iframe');
$this->assertStringContainsString('http://example.com/iframe', $iframe->attr('src'));
$this->assertStringNotContainsString('ecl-u-type-heading-2', $html);

// Assert "Full width" field.
$paragraph->set('field_oe_iframe_media_full_width', TRUE)->save();
$html = $this->renderParagraph($paragraph);
$crawler = new Crawler($html);
$iframe = $crawler->filter('figure.ecl-media-container.ecl-media-container--fullwidth.ecl-media-container--custom-ratio div.ecl-media-container__media.ecl-media-container__media--ratio-custom iframe');
$iframe = $crawler->filter('figure.ecl-media-container.ecl-media-container--fullwidth div.ecl-media-container__media iframe');
$this->assertStringContainsString('http://example.com/iframe', $iframe->attr('src'));

// Assert ratio.
Expand Down

0 comments on commit 54fd837

Please sign in to comment.