/** * Access callback for endity */ function vocabulary_access($op, $entity, $account = NULL, $entity_type = NULL) { global $user; if (!isset($account)) { $account = $user; } switch ($op) { case 'create': return user_access('administer vocabulary', $account) || user_access('create vocabulary', $account); case 'view': return user_access('administer vocabulary', $account) || user_access('view vocabulary', $account); case 'edit': case 'save': // save permission created by entity_rule.inc return user_access('administer vocabulary') || user_access('edit any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); case 'delete': return user_access('administer vocabulary') || user_access('delete any vocabulary') || (user_access('edit my own vocabulary') && ($entity->uid == $account->uid)); } }
/** * Implements hook_entity_info(). */ function drills_ch_vocabulary_entity_info() { return array( 'my_vocabulary' => array( 'label' => t('My Vocabulary'), 'entity class' => 'MyVocabularyEntity', 'controller class' => 'MyVocabulryController', 'base table' => 'my_vocabulary', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'entity_id', 'label' => 'vocabulary', ), 'bundles' => array( 'my_vocabulary' => array( 'label'=>'My Vocabulary', 'admin' => array( 'path' => 'admin/structure/my-vocabulary/manage', 'access arguments' => array('administer my vocabulary'), 'controller class' => 'EntityDefaultUIController', ), ), ), 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'module' => 'my_vocabulary', 'access callback' => 'my_vocabulary_access', ), ); }
// entity/entity.module の659行あたり function entity_access($op, $entity_type, $entity = NULL, $account = NULL) { if (($info = entity_get_info()) && isset($info[$entity_type]['access callback'])) { return $info[$entity_type]['access callback']($op, $entity, $account, $entity_type); } }