| 7 field.module | field_access($op, $field, $entity_type, $entity = NULL, $account = NULL) |
| 8 field.module | field_access($op, $field, $entity_type, $entity = NULL, $account = NULL) |
Determines whether the user has access to a given field.
Parameters
string $op: The operation to be performed. Possible values:
- edit
- view
array $field: The full field structure array for the field on which the operation is to be performed. See field_info_field().
$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; FALSE if the operation is denied.
Related topics
6 calls to field_access()
- EditEntityFieldAccessCheck::accessEditEntityField in core/
modules/ edit/ lib/ Drupal/ edit/ Access/ EditEntityFieldAccessCheck.php - Implements EntityFieldAccessCheckInterface::accessEditEntityField().
- EntityReferenceController::handleAutocomplete in core/
modules/ entity_reference/ lib/ Drupal/ entity_reference/ EntityReferenceController.php - Autocomplete the label of an entity.
- Field::access in core/
modules/ field/ lib/ Drupal/ field/ Plugin/ views/ field/ Field.php - Check whether current user has access to this handler.
- file_file_download in core/
modules/ file/ file.module - Implements hook_file_download().
- FormatterBase::view in core/
modules/ field/ lib/ Drupal/ field/ Plugin/ Type/ Formatter/ FormatterBase.php - {@inheritdoc}
File
- core/
modules/ field/ field.module, line 939 - Attach custom data fields to Drupal entities.
Code
function field_access($op, $field, $entity_type, $entity = NULL, $account = NULL) {
global $user;
if (!isset($account)) {
$account = $user;
}
foreach (module_implements('field_access') as $module) {
$function = $module . '_field_access';
$access = $function($op, $field, $entity_type, $entity, $account);
if ($access === FALSE) {
return FALSE;
}
}
return TRUE;
}