You are here

function field_collection_item_access in Field collection 7

Determines whether the given user has access to a field collection.

Parameters

$op: The operation being performed. One of 'view', 'update', 'create', 'delete'.

$item: Optionally a field collection item. If nothing is given, access for all items is determined.

$account: The user to check for. Leave it to NULL to check for the global user.

Return value

boolean Whether access is allowed or not.

1 string reference to 'field_collection_item_access'
field_collection_entity_info in ./field_collection.module
Implements hook_entity_info().

File

./field_collection.module, line 370
Module implementing field collection field type.

Code

function field_collection_item_access($op, FieldCollectionItemEntity $item = NULL, $account = NULL) {

  // We do not support editing field collection revisions that are not used at
  // the hosts default revision as saving the host might result in a new default
  // revision.
  if ($op !== 'view' && isset($item) && !$item
    ->isInUse()) {
    return FALSE;
  }
  if (user_access('edit field collections', $account)) {
    return TRUE;
  }
  if (user_access('administer field collections', $account)) {
    return TRUE;
  }
  if (!isset($item)) {
    return FALSE;
  }
  $op = $op === 'view' ? 'view' : 'edit';

  // Access is determined by the entity and field containing the reference.
  $field = field_info_field($item->field_name);
  $hostEntity = $item
    ->hostEntity() !== FALSE ? $item
    ->hostEntity() : NULL;
  $entity_access = entity_access($op === 'view' ? 'view' : 'update', $item
    ->hostEntityType(), $hostEntity, $account);
  return $entity_access && field_access($op, $field, $item
    ->hostEntityType(), $hostEntity, $account);
}