Skip to content

Commit

Permalink
EWPP-2842: Show the last item of the Timeline paragraph.
Browse files Browse the repository at this point in the history
  • Loading branch information
22Alexandra authored and upchuk committed Feb 7, 2023
1 parent c43d60b commit 7a92b87
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand Down
1 change: 1 addition & 0 deletions templates/paragraphs/paragraph--oe-timeline.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}) }}
10 changes: 5 additions & 5 deletions tests/src/Kernel/Paragraphs/TimelineParagraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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('<p>Description <strong>5</strong></p>', 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');
Expand Down

0 comments on commit 7a92b87

Please sign in to comment.