You are here

function _field_permissions_field_edit_access in Field Permissions 7

Same name and namespace in other branches
  1. 6 includes/field_access.inc \_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

./field_permissions.module, line 231
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_edit_access($field_name, $entity_type, $entity, $account) {

  // If this is a new entity, check if the user has access to edit the field on
  // entity creation.
  if (isset($entity->is_new)) {

    // Some entities provide an "is_new" property. If that is present, respect
    // whatever it's set to.
    $is_new = $entity->is_new;
  }
  else {

    // Otherwise, try to find out if the entity is new by checking its ID. Note
    // that checking empty() rather than !isset() is important here, to deal
    // with the case of entities that store "0" as their ID while the final
    // entity is in the process of being created (user accounts are a good
    // example of this).
    list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
    $is_new = empty($id);
  }
  if ($is_new) {
    return user_access('create ' . $field_name, $account);
  }

  // Check if user has access to edit this field in any entity.
  if (user_access('edit ' . $field_name, $account)) {
    return TRUE;
  }

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