1 field.api.php hook_field_access($op, $field, $entity_type, $entity, $account)

Determine whether the user has access to a given field.

This hook is invoked from field_access() to let modules block access to operations on fields. If no module returns FALSE, the operation is allowed.

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; for example, 'node' or 'user'.

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

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

Return value

TRUE if the operation is allowed, and FALSE if the operation is denied.:

Related topics

File

core/modules/field/field.api.php, line 2795
Hooks provided by the Field module.

Code

function hook_field_access($op, $field, $entity_type, $entity, $account) {
  if ($field['field_name'] == 'field_of_interest' && $op == 'edit') {
    return user_access('edit field of interest', $account);
  }
  return TRUE;
}