You are here

function entity_metadata_taxonomy_access in Entity API 7

Access callback for the taxonomy entities.

1 string reference to 'entity_metadata_taxonomy_access'
_entity_info_add_metadata in ./entity.module
Adds metadata and callbacks for core entities to the entity info.

File

modules/callbacks.inc, line 815
Provides various callbacks for the whole core module integration.

Code

function entity_metadata_taxonomy_access($op, $entity = NULL, $account = NULL, $entity_type = NULL) {

  // If user has administer taxonomy permission then no further checks.
  if (user_access('administer taxonomy', $account)) {
    return TRUE;
  }
  switch ($op) {
    case "view":
      if (user_access('access content', $account)) {
        return TRUE;
      }
      break;
    case "update":
      if ($entity_type == 'taxonomy_term') {
        return user_access("edit terms in {$entity->vid}", $account);
      }
      break;
    case "create":
      if ($entity_type == 'taxonomy_term') {

        // Check for taxonomy_access_fix contrib module which adds additional
        // permissions to create new terms in a given vocabulary.
        if (function_exists('taxonomy_access_fix_access')) {
          return taxonomy_access_fix_access('add terms', $entity->vocabulary_machine_name);
        }
      }
      break;
    case "delete":
      if ($entity_type == 'taxonomy_term') {
        return user_access("delete terms in {$entity->vid}", $account);
      }
      break;
  }
  return FALSE;
}