diff --git a/config/sync/views.view.talks.yml b/config/sync/views.view.talks.yml index ffb3588..84abe8d 100644 --- a/config/sync/views.view.talks.yml +++ b/config/sync/views.view.talks.yml @@ -7,8 +7,8 @@ dependencies: - node.type.talk - system.menu.main module: + - datetime - node - - opdavies_talks - user id: talks label: 'Talks and workshops' @@ -96,20 +96,20 @@ display: options: { } empty: { } sorts: - event_sort: - id: event_sort - table: node__field_events - field: event_sort + field_event_date_value: + id: field_event_date_value + table: node__field_event_date + field: field_event_date_value relationship: none group_type: group admin_label: '' - plugin_id: event_sort - order: ASC + plugin_id: datetime + order: DESC expose: label: '' field_identifier: '' exposed: false - granularity: second + granularity: hour arguments: { } filters: status: diff --git a/web/modules/custom/talks/src/Plugin/views/sort/Event.php b/web/modules/custom/talks/src/Plugin/views/sort/Event.php deleted file mode 100644 index 8899899..0000000 --- a/web/modules/custom/talks/src/Plugin/views/sort/Event.php +++ /dev/null @@ -1,69 +0,0 @@ -time = $time; - } - - public static function create( - ContainerInterface $container, - array $configuration, - $pluginId, - $pluginDefinition - ) { - return new static( - $configuration, - $pluginId, - $pluginDefinition, - $container->get('datetime.time') - ); - } - - public function query(): void { - $this->ensureMyTable(); - - $currentDate = Carbon::parse('today')->getTimestamp(); - - $dateAlias = "$this->tableAlias.$this->realField"; - - // Is this event in the past? - $this->query->addOrderBy( - NULL, - sprintf("%d > %s", $currentDate, $dateAlias), - $this->options['order'], - "in_past" - ); - - // How far in the past/future is this event? - $this->query->addOrderBy( - NULL, - sprintf('ABS(%s - %d)', $dateAlias, $currentDate), - $this->options['order'], - "distance_from_now" - ); - } - -} diff --git a/web/modules/custom/talks/tests/src/Kernel/TalksPageSortTest.php b/web/modules/custom/talks/tests/src/Kernel/TalksPageSortTest.php deleted file mode 100644 index 43d3dd4..0000000 --- a/web/modules/custom/talks/tests/src/Kernel/TalksPageSortTest.php +++ /dev/null @@ -1,41 +0,0 @@ -createTalk([ - 'field_event_date' => Carbon::today()->addDays(4)->getTimestamp(), - ]); - $this->createTalk([ - 'field_event_date' => Carbon::today()->subDays(2)->getTimestamp(), - ]); - $this->createTalk([ - 'field_event_date' => Carbon::today()->addDay()->getTimestamp(), - ]); - $this->createTalk([ - 'field_event_date' => Carbon::today()->subDays(10)->getTimestamp(), - ]); - - $talkIds = (new Collection(views_get_view_result('talks'))) - ->map(fn(ResultRow $row) => (int) $row->_entity->id()); - - $this->assertSame([3, 1, 2, 4], $talkIds->toArray()); - } - -}