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-2842: Show the last item of the Timeline paragraph. #1230

Merged
merged 1 commit into from
Feb 7, 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
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