Bounty Ended with 200 reputation awarded by Neograph734
4 added 495 characters in body
source | link

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(&$view) {
  global $user;

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

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

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

  // Refresh pager to reflect new count.
  $view->query->pager->total_items = count($view->result);
  $view->query->pager->update_page_info();
}

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.

Presuming your entity providing module has Views integration already setup, 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(&$view) {
  global $user;

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

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

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

  // Refresh pager to reflect new count.
  $view->query->pager->total_items = count($view->result);
  $view->query->pager->update_page_info();
}

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(&$view) {
  global $user;

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

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

        // If the custom access callback returns FALSE, remove from results.
        if (!MYMODULE_my_entity_access_callback('view', $entity, $user)) {
          unset($view->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.

3 address pager issue
source | link

Presuming your entity providing module has Views integration already setup, 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(&$view) {
  global $user;

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

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

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

  // Refresh pager to reflect new count.
  $view->query->pager->total_items = count($view->result);
  $view->query->pager->update_page_info();
}

Presuming your entity providing module has Views integration already setup, 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(&$view) {
  global $user;

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

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

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

Presuming your entity providing module has Views integration already setup, 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(&$view) {
  global $user;

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

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

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

  // Refresh pager to reflect new count.
  $view->query->pager->total_items = count($view->result);
  $view->query->pager->update_page_info();
}
2 added 60 characters in body
source | link

Presuming your entity providing module has Views integration already setup, 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(&$view) {
  global $user;

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

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

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

Presuming your entity providing module has Views integration already setup, you can invoke hook_views_pre_render() to iterate over the results and invoke your access callback for each entity in your base table:

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

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

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

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

Presuming your entity providing module has Views integration already setup, 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(&$view) {
  global $user;

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

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

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