8.5.x entity.api.php hook_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL)
8.0.x entity.api.php hook_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL)
8.1.x entity.api.php hook_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL)
8.2.x entity.api.php hook_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL)
8.3.x entity.api.php hook_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL)
8.4.x entity.api.php hook_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL)
8.6.x entity.api.php hook_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL)

Control access to fields.

This hook is invoked from \Drupal\Core\Entity\EntityAccessControlHandler::fieldAccess() to let modules grant or deny operations on fields.

Parameters

string $operation: The operation to be performed. See \Drupal\Core\Entity\EntityAccessControlHandlerInterface::fieldAccess() for possible values.

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.

\Drupal\Core\Session\AccountInterface $account: The user account to check.

\Drupal\Core\Field\FieldItemListInterface $items: (optional) The entity field object on which the operation is to be performed.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

See also

\Drupal\Core\Entity\EntityAccessControlHandlerInterface::fieldAccess()

Related topics

7 functions implement hook_entity_field_access()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

content_moderation_entity_field_access in core/modules/content_moderation/content_moderation.module
Implements hook_entity_field_access().
entity_test_entity_field_access in core/modules/system/tests/modules/entity_test/entity_test.module
Implements hook_entity_field_access().
field_test_boolean_access_denied_entity_field_access in core/modules/field/tests/modules/field_test_boolean_access_denied/field_test_boolean_access_denied.module
Implements hook_entity_field_access().
field_test_entity_field_access in core/modules/field/tests/modules/field_test/field_test.field.inc
Implements hook_entity_field_access().
language_entity_field_access in core/modules/language/language.module
Implements hook_entity_field_access()

... See full list

File

core/lib/Drupal/Core/Entity/entity.api.php, line 1964
Hooks and documentation related to entities.

Code

function hook_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, \Drupal\Core\Field\FieldItemListInterface $items = NULL) {
  if ($field_definition
    ->getName() == 'field_of_interest' && $operation == 'edit') {
    return AccessResult::allowedIfHasPermission($account, 'update field of interest');
  }
  return AccessResult::neutral();
}