From 7a92b873abd1ce635ab3caa33d3122cf86b118b5 Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Tue, 10 Jan 2023 12:09:08 +0200 Subject: [PATCH] EWPP-2842: Show the last item of the Timeline paragraph. --- oe_theme.theme | 2 ++ templates/paragraphs/paragraph--oe-timeline.html.twig | 1 + tests/src/Kernel/Paragraphs/TimelineParagraphTest.php | 10 +++++----- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/oe_theme.theme b/oe_theme.theme index f5f013dc1..e0e47b315 100644 --- a/oe_theme.theme +++ b/oe_theme.theme @@ -1504,6 +1504,8 @@ function oe_theme_preprocess_paragraph__oe_timeline(array &$variables): void { $variables['heading'] = $paragraph->get('field_oe_title')->value; } $variables['limit'] = $paragraph->get('field_oe_timeline_expand')->value; + // Show the last item of the timeline. + $variables['limit_to'] = count($variables['content']['field_oe_timeline']['#items']) - 1; $variables['items'] = $variables['content']['field_oe_timeline']['#items']; } diff --git a/templates/paragraphs/paragraph--oe-timeline.html.twig b/templates/paragraphs/paragraph--oe-timeline.html.twig index bef4d8b0a..c9c85d764 100644 --- a/templates/paragraphs/paragraph--oe-timeline.html.twig +++ b/templates/paragraphs/paragraph--oe-timeline.html.twig @@ -8,6 +8,7 @@ 'title': heading, 'introduction': content.field_oe_text_long|field_value|render|default(''), 'limit': limit, + 'limit_to': limit_to, 'button_label': show_more, 'items': items, }) }} diff --git a/tests/src/Kernel/Paragraphs/TimelineParagraphTest.php b/tests/src/Kernel/Paragraphs/TimelineParagraphTest.php index 219359947..9907c3d9b 100644 --- a/tests/src/Kernel/Paragraphs/TimelineParagraphTest.php +++ b/tests/src/Kernel/Paragraphs/TimelineParagraphTest.php @@ -116,7 +116,7 @@ public function testTimeline(): void { $this->assertCount(0, $crawler->filter('div.ecl.ecl-u-mb-m')); $this->assertCount(1, $crawler->filter('ol.ecl-timeline')); $this->assertCount(7, $crawler->filter('ol.ecl-timeline li.ecl-timeline__item')); - $this->assertCount(3, $crawler->filter('ol.ecl-timeline li.ecl-timeline__item.ecl-timeline__item--collapsed')); + $this->assertCount(2, $crawler->filter('ol.ecl-timeline li.ecl-timeline__item.ecl-timeline__item--collapsed')); $this->assertCount(1, $crawler->filter('ol.ecl-timeline li.ecl-timeline__item.ecl-timeline__item--toggle button.ecl-button.ecl-button--secondary.ecl-timeline__toggle')); $this->assertEquals('Label 1', trim($crawler->filter('ol.ecl-timeline li.ecl-timeline__item:nth-child(1) div.ecl-timeline__label')->html())); @@ -139,10 +139,10 @@ public function testTimeline(): void { $this->assertEquals('Title 5', trim($crawler->filter('ol.ecl-timeline li.ecl-timeline__item.ecl-timeline__item--collapsed:nth-child(5) div.ecl-timeline__title')->html())); // Explicit format "full_html" specified. $this->assertEquals('

Description 5

', trim($crawler->filter('ol.ecl-timeline li.ecl-timeline__item.ecl-timeline__item--collapsed:nth-child(5) div.ecl-timeline__content')->html())); - $this->assertEquals('Label 6', trim($crawler->filter('ol.ecl-timeline li.ecl-timeline__item.ecl-timeline__item--collapsed:nth-child(6) div.ecl-timeline__label')->html())); - $this->assertEquals('Title 6', trim($crawler->filter('ol.ecl-timeline li.ecl-timeline__item.ecl-timeline__item--collapsed:nth-child(6) div.ecl-timeline__title')->html())); - $this->assertEquals('Description 6', trim($crawler->filter('ol.ecl-timeline li.ecl-timeline__item.ecl-timeline__item--collapsed:nth-child(6) div.ecl-timeline__content')->html())); - $this->assertEquals('Show 3 more items', trim($crawler->filter('button.ecl-button.ecl-button--secondary.ecl-timeline__toggle span.ecl-button__container span.ecl-button__label')->html())); + $this->assertEquals('Label 6', trim($crawler->filter('ol.ecl-timeline li.ecl-timeline__item:nth-child(7) div.ecl-timeline__label')->html())); + $this->assertEquals('Title 6', trim($crawler->filter('ol.ecl-timeline li.ecl-timeline__item:nth-child(7) div.ecl-timeline__title')->html())); + $this->assertEquals('Description 6', trim($crawler->filter('ol.ecl-timeline li.ecl-timeline__item:nth-child(7) div.ecl-timeline__content')->html())); + $this->assertEquals('Show 2 more items', trim($crawler->filter('button.ecl-button.ecl-button--secondary.ecl-timeline__toggle span.ecl-button__container span.ecl-button__label')->html())); // Increase limit to print all the items and fill in optional fields. $paragraph->set('field_oe_timeline_expand', '6');