From 97050c7f29925c3f6011a48d9fb4fd08afbc5454 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 28 Oct 2017 02:28:44 +0100 Subject: [PATCH] Move more logic into Twig filter --- source/_includes/talk/events.html.twig | 14 +++++--------- source/talks.html.twig | 13 ++----------- source/talks/archive.html.twig | 13 ++----------- .../src/Twig/FormatTalksExtension.php | 19 +++++++++++++++---- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/source/_includes/talk/events.html.twig b/source/_includes/talk/events.html.twig index 8de2ca34..ed3f953a 100644 --- a/source/_includes/talk/events.html.twig +++ b/source/_includes/talk/events.html.twig @@ -1,13 +1,9 @@

Events

- {% set talks = [] %} - {% for event in page.events %} - {% set talks = talks|merge([{ - event: event|merge(site.events[event.event]), - talk: page, - }]) %} - {% endfor %} - - {% include "talks-table" with { talk_page: true } %} + {% set data = { talks: [page], events: site.events } %} + {% include "talks-table" with { + talks: data|format_talks|reverse, + talk_page: true + } %}
diff --git a/source/talks.html.twig b/source/talks.html.twig index ee3dd122..9c27e5b0 100644 --- a/source/talks.html.twig +++ b/source/talks.html.twig @@ -10,18 +10,9 @@ use: [talks]

Last 5 Talks

- {% set talks = [] %} - {% for talk in data.talks %} - {% for event in talk.events %} - {% set talks = talks|merge([{ - event: event|merge(site.events[event.event]), - talk: talk, - }]) %} - {% endfor %} - {% endfor %} - + {% set data = { talks: data.talks, events: site.events } %} {% include "talks-table" with { - talks: talks|format_talks|slice(0,5) + talks: data|format_talks|slice(0,5) } %}

Upcoming talks can be found in the talks archive.

diff --git a/source/talks/archive.html.twig b/source/talks/archive.html.twig index 777deb1d..4c006a71 100644 --- a/source/talks/archive.html.twig +++ b/source/talks/archive.html.twig @@ -14,16 +14,7 @@ talks: ---

Here are a list of my previous conference and user group talks:

-{% set talks = [] %} -{% for talk in data.talks|merge(page.talks) %} - {% for event in talk.events %} - {% set talks = talks|merge([{ - event: event|merge(site.events[event.event]), - talk: talk, - }]) %} - {% endfor %} -{% endfor %} - -{% include 'talks-table' with { talks: talks|format_talks } %} +{% set data = { talks: data.talks|merge(page.talks), events: site.events } %} +{% include "talks-table" with { talks: data|format_talks } %}

Upcoming talks can be found on the talks page].

diff --git a/src/format-talks-bundle/src/Twig/FormatTalksExtension.php b/src/format-talks-bundle/src/Twig/FormatTalksExtension.php index 85e4730d..f7dbe8fe 100644 --- a/src/format-talks-bundle/src/Twig/FormatTalksExtension.php +++ b/src/format-talks-bundle/src/Twig/FormatTalksExtension.php @@ -17,11 +17,22 @@ class FormatTalksExtension extends Twig_Extension ]; } - public function formatTalks($talks) + public function formatTalks($data) { - return collect($talks) - ->sortByDesc('event.date') - ->all(); + $event_data = $data['events']; + + $talks = []; + foreach ($data['talks'] as $talk) { + foreach ($talk['events'] as $event) { + $event = array_merge($event, $event_data[$event['event']]); + + $talks[] = compact('talk', 'event'); + } + } + + return collect($talks) + ->sortByDesc('event.date') + ->all(); } /**