How to check for entity access when displaying views fields? I have a custom entity. There is an access callback defined in hook_entity_info() and it is called when I access the entity. Also in views when I select to display rendered entities, the entity is only shown when the user is allowed to see the entity.

However when I change the view to show 'fields' instead of 'rendered entities', the access callback is no longer called and users can see all fields (and properties) of the entity, regardless of any permissions. Looking at the executed query this makes sense, the field values are joined in and the entity is never really loaded.

So, how should one implement entity access for views when displaying fields (in Drupal 7)?

I've found How to check for entity type in Views when using hook_field_access?, but I assume that only works for joined fields and not for base entity properties, so that would be only a part of a solution.
Presuming your entity providing module has Views integration already setup, and you're not worried about pagination, you can
invoke hook_views_pre_render() to iterate over the results and invoke your access callback for each entity in your base table and filter out entries that the user doesn't have access to:

/**
 * Implements hook_views_pre_render().
 */
function MYMODULE_views_pre_render(&amp;$view) {
  global $user;

  // Iterate over View results for our custom entity
  if ($view-&gt;base_table == 'my_entity_base_table') {
    foreach ($view-&gt;result as $index =&gt; $row) {

      // Presuming eid is the entity PK
      $results = entity_load('my_entity_machine_name', array($row-&gt;eid));
      if (!empty($results)) {
        $entity = $results[$row-&gt;eid];

        // If the custom access callback returns FALSE, remove from results.
        if (!MYMODULE_my_entity_access_callback('view', $entity, $user)) {
          unset($view-&gt;result[$index]);
        }
      }
    }
  }
}


If pagination is a concern, it's a tougher problem; adjusting the view results break consistent offsetting (e.g. page 1 might return 4 results, page 2 might return 10 results). Plus, the results of SQL query can't adjust for information that is only known by executing PHP. 

In those instances, you'll have to adjust your method (e.g. hook_views_query_alter() if the access callback is DB query based, altering your View pager options, etc.) to accommodate for the access callback manipulating the view.