This is an example implementation of a custom views sort handler for Drupal 8.
It's meant to sort events in a way that shows users the most interesting events first:
- Future events come before past events
- Events closest to today come before events far in the past or future
To use / try this module,
- download the contents of this repository and rename it to event_sort.
- put the directory in Drupal's modules directory.
- set up a content type with a date field field_date or if you want to work with some other date field which you already might have setup, then make the necessary modifications to the module's code.
- enable the module and I believe things should work.
Note that this is a sample of a custom module. The hook_views_data_alter() assumes the field name is field_date, but if that's not the case in your project, you can write a custom hook_views_data_alter() that applies it to a different field or property.