You are here

function field_permissions_field_access in Field Permissions 7

Same name and namespace in other branches
  1. 6 field_permissions.module \field_permissions_field_access()

Implementation of hook_field_access().

Parameters

$op: The operation to be performed. Possible values:

  • 'edit'
  • 'view'

$field: The field on which the operation is to be performed.

$entity_type: The type of entity; e.g. 'node' or 'user'.

$entity: The entity on which the operation is to be performed.

$account: The account to check.

Return value

FALSE if the operation is not allowed. Note when field_access() is invoked, access is granted unless one implementation of hook_field_access() explicitly returns FALSE.

See also

field_access()

File

./field_permissions.module, line 112
This is the main script for the Field Permissions module. It merely contains the implementation of hooks invoked by Drupal core and CCK. All common functions are externalized into several scripts that are included on demand to save memory consumption…

Code

function field_permissions_field_access($op, $field, $entity_type, $entity, $account) {

  // Ignore the request if permissions have not been enabled for this field.
  if (!isset($field['field_permissions']['type']) || $field['field_permissions']['type'] == FIELD_PERMISSIONS_PUBLIC) {
    return;
  }
  elseif ($field['field_permissions']['type'] == FIELD_PERMISSIONS_PRIVATE) {
    if (isset($entity)) {
      return _field_permissions_entity_is_owned_by_account($entity, $account) || user_access('access private fields', $account);
    }
    else {
      return TRUE;
    }
  }
  elseif ($field['field_permissions']['type'] == FIELD_PERMISSIONS_CUSTOM) {

    // Allow other modules to deny access first.
    $result = module_invoke_all('field_permissions_custom_field_access', $op, $field, $entity_type, $entity, $account);
    if (in_array(FALSE, $result)) {
      return FALSE;
    }
    if (!isset($entity)) {
      return field_permissions_empty_entity_access($op, $field['field_name'], $account);
    }
    elseif ($op == 'view') {
      return _field_permissions_field_view_access($field['field_name'], $entity_type, $entity, $account);
    }
    elseif ($op == 'edit') {
      return _field_permissions_field_edit_access($field['field_name'], $entity_type, $entity, $account);
    }
  }
}