You are here

function _field_permissions_field_edit_access in Field Permissions 6

Same name and namespace in other branches
  1. 7 field_permissions.module \_field_permissions_field_edit_access()

Implementation of hook_field_access('edit').

1 call to _field_permissions_field_edit_access()
field_permissions_field_access in ./field_permissions.module
Implementation of hook_field_access().

File

includes/field_access.inc, line 62
Implementation of helper functions related to hook_field_access().

Code

function _field_permissions_field_edit_access($field_name, $field_permissions, $account, $node) {

  // Check if user has access to edit this field on node creation.
  if (empty($node->nid) && !empty($field_permissions['create'])) {
    return user_access('create ' . $field_name, $account);
  }

  // Check if user has access to edit this field in any node.
  if (!empty($field_permissions['edit']) && user_access('edit ' . $field_name, $account)) {
    return TRUE;
  }

  // If 'edit own' permission has been enabled for this field, then we can
  // check if the user has the right permission, and ownership of the node.
  if (!empty($field_permissions['edit own']) && user_access('edit own ' . $field_name, $account) && $node->uid == $account->uid) {
    return TRUE;
  }
  return FALSE;
}