Skip to content

Commit

Permalink
Merge pull request #1263 from openeuropa/EWPP-3083
Browse files Browse the repository at this point in the history
EWPP-3083: Make timeline field always show the last item.
  • Loading branch information
upchuk authored May 11, 2023
2 parents cb8c898 + f5c6444 commit a426fec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function viewElements(ContentEntityInterface $entity) {
}

$build['#fields']['items'] = $items;
$build['#fields']['limit_to'] = count($items) - 1;
$cache->addCacheContexts(['timezone']);
$cache->applyTo($build);

Expand Down
1 change: 1 addition & 0 deletions templates/field/timeline.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#}
{{ pattern('timeline', {
'limit': limit,
'limit_to': items | length - 1,
'button_label': show_more,
'items': items,
}) }}
14 changes: 10 additions & 4 deletions tests/src/Kernel/TimelineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ public function testTimelineRender(): void {
'body' => 'Item 3 body',
'format' => 'my_text_format',
],
[
'label' => '16/07/2019',
'title' => 'Item 4',
'body' => 'Item 4 body',
'format' => 'my_text_format',
],
],
];

Expand All @@ -176,16 +182,16 @@ public function testTimelineRender(): void {
// Assert the timeline items are the number of entries plus one for the
// "See more" button.
$timeline_item = $crawler->filter('.ecl-timeline__item');
$this->assertCount(4, $timeline_item);
$this->assertCount(5, $timeline_item);

$timeline_body = $crawler->filter('.ecl-timeline__label');
$this->assertCount(3, $timeline_body);
$this->assertCount(4, $timeline_body);

$timeline_title = $crawler->filter('.ecl-timeline__title');
$this->assertCount(3, $timeline_title);
$this->assertCount(4, $timeline_title);

$timeline_body = $crawler->filter('.ecl-timeline__content');
$this->assertCount(3, $timeline_body);
$this->assertCount(4, $timeline_body);

$hidden_timeline_item = $crawler->filter('.ecl-timeline__item--collapsed');
$this->assertCount(1, $hidden_timeline_item);
Expand Down

0 comments on commit a426fec

Please sign in to comment.