How can I ensure that fields from a Views query plugin work as tokens? I have a Drupal 7 Views query plugin module that pulls in data from a RESTful API for use in Views. I used this series of articles as a starting point to build it: https://www.lullabot.com/articles/building-views-query-plugins. I now need to port it to Drupal 8.

I have made a start on the porting process, with the help of this series of articles: https://www.lullabot.com/articles/building-views-query-plugins-dupal-8-part-1. The Drupal 8 module now successfully pulls in data for the fields that use the 'standard' handler.

I'm currently stuck on trying to get tokens representing one of those fields to work when rewriting results.

The field is called access-url and contains URLs. If I tick 'Override the output of this field with custom text' on that field, and enter the token form, {{ access-url }}, it just returns '0' for every record, whereas if I untick that box it returns the URLs correctly. Meanwhile, the token form of the id field works correctly.

(In real life I will want to use {{ access-url }} under 'Output this field as a custom link', but 'Override the output of this field with custom text' illustrates the problem better.)

How can I get the {{ access-url }} token to work correctly?

I expect it would be helpful if I posted some code, but I'm not sure what code would be most helpful, so please let me know.

Additional debugging info: as far as I can tell, all seems well until it gets to the line in PluginBase::viewsTokenReplace() that runs $this-&gt;getRenderer()-&gt;renderPlain($build). $build at that point has the value of access-url in it, but the renderer returns zero.
Eventually I realised that it was only tokens containing hyphens that weren't working, and sure enough, it turns out that hyphens are not allowed in Twig tokens. Or, to be more accurate, they are interpreted as minus signs (https://www.drupal.org/project/drupal/issues/2371633). That was why the {{ access-url }} token was returning zero: access minus url equals zero, apparently. So I just replaced all of the hyphens with underscores.