Content acces basing on a field value
this is how i did it ( simplified for demo purpose )

function my_module_node_access(NodeInterface $node, $op, AccountInterface $account) {

global $user;
$user = \Drupal\user\Entity\User::load($account-&gt;id());

  if ($node-&gt;bundle() == 'my_content_type') {
    if ($op == 'view') {
        $visibility=$node-&gt;field_visibilite-&gt;getString();
        $target=$node-&gt;field_target-&gt;getString();


        if ($visibility ==='all')
            return \Drupal\Core\Access\AccessResult::allowed();

        if ($visibility ==='restricted') 
            if (($target === 'group1') &amp;&amp; ($user-&gt;hasRole('group1')))
                return \Drupal\Core\Access\AccessResult::allowed();


}

 return \Drupal\Core\Access\AccessResult::forbidden();

}