In reference to this post -> https://www.drupal.org/node/1374150

node-like permissions to custom entities? e.g. "view own", "edit own", "delete own", "view all", etc. Is it possible? What is the best approach to go about building it?

Comments

kristianb21’s picture

Category: Support request » Feature request
Issue summary: View changes
fmizzell’s picture

Version: 7.x-2.0-rc6 » 7.x-2.x-dev
Yuri’s picture

Priority: Minor » Normal
longwave’s picture

This is doable with a bit of custom code, adapt as needed - in my case I didn't care about specific permissions, just entity ownership:

/**
 * Implements hook_entity_info_alter().
 */
function MODULE_entity_info_alter(&$entity_info) {
  $entity_info['ENTITY']['access callback'] = 'MODULE_ENTITY_access';
}

/**
 * Entity access callback.
 */
function MODULE_ENTITY_access($op, $entity, $account, $entity_type) {
  switch ($op) {
    case 'view':
    case 'update':
    case 'delete':
      if ($entity->uid == $GLOBALS['user']->uid) {
        return TRUE;
      }
      break;
  }

  return eck__entity_access($op, $entity, $account, $entity_type);
}
kingandy’s picture

Weirdly, ECK seems to halfway offer 'own' management functionality. When the $b_own argument for eck__multiple_access_check() is set to TRUE, for each permission in the passed-in array, it also checks for one with the same name appended with " own". So for example, if a menu callback was checking for "eck administer my_type my_bundle entities" and "eck edit my_type my_bundle entities", it would also check "eck administer my_type my_bundle entities own" and "eck edit my_type my_bundle entities own".

But, ECK itself doesn't actually declare those '... own' permissions in hook_permission, and I've not found anywhere that actually uses $b_own = TRUE, so I guess it never got fully implemented (or is a vestige of an earlier 'own' permission model).