Fix the ordering for future talks

Rather than the custom event sorting plugin being based on the `created`
value, this change adds a new `field_event_date` field to the talk node
type and uses this for the sorting instead.

This commit also adds a new `TalkDateUpdater` service that extracts
either the next event date if there is a future date, or the last past
event date if there is no future date, from `field_events` for each talk
and saves it into the event date field.

For consistency, and to ensure that the results are ordered correctly,
the talk date updater converts the date from a date string (e.g.
`2020-08-24`) into a UNIX timestamp, and the timestamp is saved in the
event date field. This can be changed at a later date if needed.

The talks view has been updated to use the updated sort plugin, and the
existing tests have been updated to use the new field.

References #204
This commit is contained in:
Oliver Davies 2020-08-24 02:00:22 +01:00
parent bdf225b05d
commit 6d9ecd8df0
17 changed files with 340 additions and 21 deletions

View file

@ -11,12 +11,12 @@ declare(strict_types=1);
* Implements hook_views_data_alter().
*/
function opd_talks_views_data_alter(array &$data): void {
$data['node_field_data']['event_sort'] = [
$data['node__field_event_date']['event_sort'] = [
'title' => t('Custom event sort'),
'group' => t('Content'),
'help' => t('Sort events by past/future, then distance from now.'),
'sort' => [
'field' => 'created',
'field' => 'field_event_date_value',
'id' => 'event_sort',
]
];