You are here

function hook_field_permissions_custom_field_access in Field Permissions 7

Hook invoked with custom field permissions.

This hook can be used to revoke access to the field. If access is not revoked, default access of the Field permissions module will apply.

Parameters

string $op: The operation to be performed. Possible values: 'edit', 'view'.

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

string $entity_type: The type of $entity; for example, 'node' or 'user'.

object $entity: (optional) The entity for the operation.

object $account: (optional) The account to check; if not given use currently logged in user.

Return value

bool FALSE if the operation is not allowed.

See also

field_permissions_field_access()

field_access()

1 invocation of hook_field_permissions_custom_field_access()
field_permissions_field_access in ./field_permissions.module
Implementation of hook_field_access().

File

./field_permissions.api.php, line 70
Hooks provided by the Field Permission module.

Code

function hook_field_permissions_custom_field_access($op, $field, $entity_type, $entity, $account) {
  if ($op == 'view' && $entity_type == 'node' && !empty($entity)) {

    // Check if user has access to view this field in any entity.
    if (!user_access('view node preview ' . $field['field_name'], $account)) {
      return FALSE;
    }

    // If the user has permission to view entities that they own, return TRUE if
    // they own this entity or FALSE if they don't.
    if (user_access('view own node preview ' . $field['field_name'], $account)) {
      return _field_permissions_entity_is_owned_by_account($entity, $account);
    }
  }
  return TRUE;
}