Hide certain nodes in view listing for anonymous users I am trying to restrict node access for anonymous users based on a custom field. 
I got it working for accessing the node directly like this:

$country = "GB";
if ($node-&gt;hasField('field_country_hide')) {
  $country_code = $node-&gt;field_country_hide-&gt;value;

  if ($country_code == $country) {
    // this user should not be allowed to see this article
    return AccessResult::forbidden();
  }
} else {
  return AccessResult::neutral();
}


But this doesn't restrict access for the node in a view listing. 
What is the best way to go about hiding a node in a view listing?
Drupal doesn't evoke hook_node_access() when executing a view; it's querying the DB directly to get the data. As such, you're not going to be able evoke the same PHP snippet to have Views filter the result.  

The "best" way (read: simple) is to have views create a query filter that does the same thing; you can add a  Content: Country Hide filter (or whatever your custom field is named) with the Operator set to Is equal to and the Value set to GB.

That will filter the nodes as you need, but you'll still need to provide the context (i.e. is the user anonymous or not). Here it's unclear. There's no "best" because there's not one way to provide context and it will depend on your needs. 

One idea that comes to mind is to add 2 View blocks, one with the GB filter and one without, and set the block to display depending on the user role. But again, this will depend on your requirements. There's always custom Views integration or, if you want to go the site builder route, other modules that provide context like Context, Panels, etc.