php contextual filter alternative in a Drupal 8 view

I understand that using the php option to return a value for a contextual filter is frowned upon, but I have an inherited Drupal 6 site I’m attempting to upgrade to 8, which has several views that use this method.

An example of a php contextual filter can be seen here for Drupal 7:
https://www.drupal.org/docs/7/modules/views/views-howtos/php-contextual-…

Can anyone recommend a straight forward alternative to providing a more advanced way of returning a value for a contextual filter to use?

I’ve tried using hook_views_query_alter() and using addWhere() and leftJoin() within that to try to re-write the query to match what the contextual filter would be, but this is an infinitely more time consuming and complex way of approaching it, so am really looking for a way to reference some php somehow for a contextual filter to return.

Any suggestions would be really appreciated!

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/22/feed