Q:

What is the equivalent of hook_user_view()?

I am basically trying to do what described in How can I let anonymous users view user profiles by role? in Drupal 8. User profiles should only be visible to anonymous users only if those profiles are for users having a certain role; all the other user profiles should not be accessible to anonymous.
The answer there suggests using hook_user_view(), but it appears that hook has been removed in Drupal 8. Is there a different/correct way to do this now?

A:

hook_user_view() is still available in drupal 8, but the hook naming schema has changed, because the hook can now be used for all entity types:
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!entity.api.php/function/hook_ENTITY_TYPE_view/8.2.x
A more D8 way to do this could be a custom access check on the route:
https://www.drupal.org/node/2122195

A:

4k4's link is a really good resource for access checking for custom routes.
Another option would be to implement hook_entity_access in your own custom module. I just tested this and it does what you originally asked for:
/**
 * Implements hook_entity_access().
 */
function  MYMODULE_entity_access(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Session\AccountInterface $account) {
  if ($entity->getEntityType()->id() == 'user' && !$account->id()) {
    if (!$entity->hasRole('administrator')) {
      return \Drupal\Core\Access\AccessResult::forbidden();
    }
  }
}

Obviously, change administrator with the machine name of the role you are looking to grant access too.  You do need to give anonymous users the permsission to view user information also. This just limits the entities (users) they are allowed to view.

