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-3498: Avoid using the same highlighted field valu for illustration lists. #1312

Merged
merged 2 commits into from
Sep 11, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,18 @@ public function testFormatter(): void {
$this->assertEmpty($caption->filter('.ecl-gallery__meta')->html());

// Test the second gallery item.
$this->assertStringStartsWith(
'/media/oembed?url=https%3A//www.youtube.com/watch%3Fv%3D1-g73ty9v04&max_width=0&max_height=0&hash=',
$items->eq(1)->filter('.ecl-gallery__item-link')->attr('data-ecl-gallery-item-embed-src')
);
if (version_compare(\Drupal::VERSION, '10.1', '>=')) {
$this->assertStringStartsWith(
'http://localhost/media/oembed?url=https%3A//www.youtube.com/watch%3Fv%3D1-g73ty9v04&max_width=0&max_height=0&hash=',
$items->eq(1)->filter('.ecl-gallery__item-link')->attr('data-ecl-gallery-item-embed-src')
);
}
else {
$this->assertStringStartsWith(
'/media/oembed?url=https%3A//www.youtube.com/watch%3Fv%3D1-g73ty9v04&max_width=0&max_height=0&hash=',
$items->eq(1)->filter('.ecl-gallery__item-link')->attr('data-ecl-gallery-item-embed-src')
);
}

$expected_thumbnail_name = 'FRPRzhRHyt8zGp5-d-luvJDnIb03oXDJUp5LtL4UeDI.jpg';

Expand Down Expand Up @@ -312,10 +320,18 @@ public function testFormatter(): void {
$this->assertStringContainsString($image_media->label(), $caption->html());

// Test the second gallery item.
$this->assertStringStartsWith(
'/media/oembed?url=https%3A//www.youtube.com/watch%3Fv%3D1-g73ty9v04&max_width=0&max_height=0&hash=',
$items->eq(1)->filter('.ecl-gallery__item-link')->attr('data-ecl-gallery-item-embed-src')
);
if (version_compare(\Drupal::VERSION, '10.1', '>=')) {
$this->assertStringStartsWith(
'http://localhost/media/oembed?url=https%3A//www.youtube.com/watch%3Fv%3D1-g73ty9v04&max_width=0&max_height=0&hash=',
$items->eq(1)->filter('.ecl-gallery__item-link')->attr('data-ecl-gallery-item-embed-src')
);
}
else {
$this->assertStringStartsWith(
'/media/oembed?url=https%3A//www.youtube.com/watch%3Fv%3D1-g73ty9v04&max_width=0&max_height=0&hash=',
$items->eq(1)->filter('.ecl-gallery__item-link')->attr('data-ecl-gallery-item-embed-src')
);
}
$image_node = $items->eq(1)->filter('img');
$this->assertEquals("Energy, let's save it!", $image_node->attr('alt'));
$this->assertStringContainsString(
Expand Down
15 changes: 9 additions & 6 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -1934,16 +1934,17 @@ function oe_theme_preprocess_paragraph__oe_illustration_list_flags(array &$varia
// Get sub-paragraph translation.
$sub_paragraph = \Drupal::service('entity.repository')
->getTranslationFromContext($sub_paragraph, $paragraph->language()->getId());
$highlight = '';
$icon = $sub_paragraph->get('field_oe_flag')->value;
$icon .= $ratio === 'square' ? '-square' : '';
if ($sub_paragraph->hasField('field_oe_subtitle') && !$sub_paragraph->get('field_oe_subtitle')->isEmpty()) {
$highlight = $sub_paragraph->get('field_oe_subtitle')->value;
$highlight = $sub_paragraph->get('field_oe_subtitle')->isEmpty() ? '' : $builder->viewField($sub_paragraph->get('field_oe_subtitle'));
}
$variables['items'][] = [
'title' => $sub_paragraph->get('field_oe_title')->value,
'description' => $sub_paragraph->get('field_oe_text_long')->isEmpty() ? '' : $builder->viewField($sub_paragraph->get('field_oe_text_long')),
'icon' => $icon,
'value' => $highlight ?? '',
'value' => $highlight,
];
}
}
Expand All @@ -1965,15 +1966,16 @@ function oe_theme_preprocess_paragraph__oe_illustration_list_icons(array &$varia
// Get sub-paragraph translation.
$sub_paragraph = \Drupal::service('entity.repository')
->getTranslationFromContext($sub_paragraph, $paragraph->language()->getId());
$highlight = '';
if ($sub_paragraph->hasField('field_oe_subtitle') && !$sub_paragraph->get('field_oe_subtitle')->isEmpty()) {
$highlight = $sub_paragraph->get('field_oe_subtitle')->value;
$highlight = $sub_paragraph->get('field_oe_subtitle')->isEmpty() ? '' : $builder->viewField($sub_paragraph->get('field_oe_subtitle'));
}
$variables['items'][] = [
'title' => $sub_paragraph->get('field_oe_title')->value,
'description' => $sub_paragraph->get('field_oe_text_long')->isEmpty() ? '' : $builder->viewField($sub_paragraph->get('field_oe_text_long')),
'icon' => $sub_paragraph->get('field_oe_icon')->value,
'media_size' => $size ?? 'm',
'value' => $highlight ?? '',
'value' => $highlight,
];
}
}
Expand Down Expand Up @@ -2020,15 +2022,16 @@ function oe_theme_preprocess_paragraph__oe_illustration_list_images(array &$vari
$image = ImageValueObject::fromStyledImageItem($thumbnail, 'oe_theme_medium_no_crop');
}
}
$highlight = '';
if ($sub_paragraph->hasField('field_oe_subtitle') && !$sub_paragraph->get('field_oe_subtitle')->isEmpty()) {
$highlight = $sub_paragraph->get('field_oe_subtitle')->value;
$highlight = $sub_paragraph->get('field_oe_subtitle')->isEmpty() ? '' : $builder->viewField($sub_paragraph->get('field_oe_subtitle'));
}
$variables['items'][] = [
'title' => $sub_paragraph->get('field_oe_title')->value,
'description' => $sub_paragraph->get('field_oe_text_long')->isEmpty() ? '' : $builder->viewField($sub_paragraph->get('field_oe_text_long')),
'image' => $image ?? '',
'media_size' => $size ?? 'm',
'value' => $highlight ?? '',
'value' => $highlight,
];
}

Expand Down
13 changes: 4 additions & 9 deletions tests/src/Kernel/Paragraphs/IllustrationListsParagraphsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public function testIllustrationListFlagsRendering(): void {
'type' => 'oe_illustration_item_flag',
'field_oe_subtitle' => 'Highlighted Term 2',
'field_oe_title' => 'Term 2',
'field_oe_text_long' => '',
'field_oe_flag' => 'belgium',
]);
$paragraph->save();
Expand All @@ -86,7 +85,6 @@ public function testIllustrationListFlagsRendering(): void {
$paragraph = Paragraph::create([
'type' => 'oe_illustration_item_flag',
'field_oe_subtitle' => 'Highlighted Term 3',
'field_oe_title' => '',
'field_oe_text_long' => 'Description 3',
'field_oe_flag' => 'france',
]);
Expand All @@ -95,8 +93,6 @@ public function testIllustrationListFlagsRendering(): void {

$paragraph = Paragraph::create([
'type' => 'oe_illustration_item_flag',
'field_oe_title' => '',
'field_oe_text_long' => '',
'field_oe_flag' => 'finland',
]);
$paragraph->save();
Expand Down Expand Up @@ -162,9 +158,11 @@ public function testIllustrationListFlagsRendering(): void {
], [
'title' => 'Term 2',
'icon' => 'belgium-square',
'value' => 'Highlighted Term 2',
], [
'description' => 'Description 3',
'icon' => 'france-square',
'value' => 'Highlighted Term 3',
], [
'icon' => 'finland-square',
],
Expand Down Expand Up @@ -226,7 +224,7 @@ public function testIllustrationListIconsRendering(): void {

$paragraph = Paragraph::create([
'type' => 'oe_illustration_item_icon',
'field_oe_subtitle' => 'Highlighted Term 4',
'field_oe_text_long' => 'Description 4',
'field_oe_icon' => 'package',
]);
$paragraph->save();
Expand Down Expand Up @@ -272,7 +270,7 @@ public function testIllustrationListIconsRendering(): void {
'media_size' => 'l',
], [
'icon' => 'package',
'value' => 'Highlighted Term 4',
'description' => 'Description 4',
'media_size' => 'l',
],
],
Expand Down Expand Up @@ -351,7 +349,6 @@ public function testIllustrationListImagesRendering(): void {

$paragraph = Paragraph::create([
'type' => 'oe_illustration_item_image',
'field_oe_subtitle' => 'Highlighted Term 1',
'field_oe_title' => 'Term 2',
'field_oe_media' => [$media_av_portal_photo],
]);
Expand Down Expand Up @@ -412,7 +409,6 @@ public function testIllustrationListImagesRendering(): void {
'src' => 'files/styles/oe_theme_medium_no_crop/public/media_avportal_thumbnails/' . $av_portal_photo_file->getFilename(),
'alt' => 'Euro with miniature figurines',
],
'value' => 'Highlighted Term 2',
], [
'description' => 'Description 3',
'image' => [
Expand All @@ -424,7 +420,6 @@ public function testIllustrationListImagesRendering(): void {
'src' => 'styles/oe_theme_medium_no_crop/public/example_1.jpeg',
'alt' => 'Alt',
],
'value' => 'Highlighted Illustration list with images',
],
],
'centered' => FALSE,
Expand Down
6 changes: 6 additions & 0 deletions tests/src/PatternAssertions/ListWithIllustrationAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ protected function assertItems(array $expected_items, Crawler $crawler): void {
else {
self::assertElementNotExists('.ecl-list-illustration__title', $item_element);
}
if (isset($expected_item['value'])) {
self::assertElementText($expected_item['value'], '.ecl-list-illustration__value', $item_element);
}
else {
self::assertElementNotExists('.ecl-list-illustration__value', $item_element);
}
if (isset($expected_item['description'])) {
self::assertElementText($expected_item['description'], '.ecl-list-illustration__description', $item_element);
}
Expand Down