Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294185

Expand the node grants system to a generic entity grants system

$
0
0

Before:

db_select('node')->addTag('node_access')->execute();
$access = node_access('view', $node, $account);

After:

db_select('node')->addTag('entity_access')->addMetaData('entity', 'node')->execute();
$access = entity_access('node', $node, 'view', $account); //Parameter order subject to bikeshed

function entity_access($entity_type, $entity, $op, stdClass $account) {
  $info = entity_get_info($entity_type);
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);

  // A bundle-specific callback takes precedence over the generic one for the
  // entity type.
  if (isset($info['bundles'][$bundle]['access callback'])) {
    $access_callback = $info['bundles'][$bundle]['access callback'];
  }
  elseif (isset($info['access callback'])) {
    $access_callback = $info['access callback'];
  }
  else {
    $access_callback = NULL;
  }

  if (isset($access_callback) && funciton_exists($access_callback)) {
    return $access_callback($entity, $op, $account);
  }

  // If there is no access callback, default to allowing access.
  return TRUE;
}

We should take advantage of an 'access callback' in the entity info for each entity.

Related issues

#1810320: Remove EntityTranslationControllerInterface::getAccess() once have entity access is postponed on this issue.


Viewing all articles
Browse latest Browse all 294185

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>