field_access

Versions
7
field_access($op, $field, $obj_type, $object = NULL, $account = NULL)

Determine whether the user has access to a given field.

Parameters

$op The operation to be performed. Possible values:

  • "edit"
  • "view"

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

$obj_type The type of $object; e.g. 'node' or 'user'.

$object (optional) The object 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; FALSE if the operation is denied.

Related topics

▾ 3 functions call field_access()

field_default_form in modules/field/field.form.inc
Create a separate form element for each field.
field_default_view in modules/field/field.default.inc
Default field 'view' operation.
field_format in modules/field/field.module
Format a field item for display.

Code

modules/field/field.module, line 643

<?php
function field_access($op, $field, $obj_type, $object = NULL, $account = NULL) {
  global $user;

  if (is_null($account)) {
    $account = $user;
  }

  $field_access = module_invoke_all('field_access', $op, $field, $obj_type, $object, $account);
  foreach ($field_access as $value) {
    if ($value === FALSE) {
      return FALSE;
    }
  }
  return TRUE;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.