function hook_entity_field_access
Same name and namespace in other branches
- 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_field_access()
- 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_field_access()
- 11.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_field_access()
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 for which to check access, or NULL if access is checked for the field definition, without any specific value available. Defaults to NULL.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
See also
\Drupal\Core\Entity\EntityAccessControlHandlerInterface::fieldAccess()
Related topics
24 functions implement hook_entity_field_access()
Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.
- ContentModerationHooks::entityFieldAccess in core/
modules/ content_moderation/ src/ Hook/ ContentModerationHooks.php - Implements hook_entity_field_access().
- content_moderation_entity_field_access in core/
modules/ content_moderation/ content_moderation.module - Implements hook_entity_field_access().
- EntityTestHooks::entityFieldAccess in core/
modules/ system/ tests/ modules/ entity_test/ src/ Hook/ EntityTestHooks.php - 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().
- FieldTestBooleanAccessDeniedHooks::entityFieldAccess in core/
modules/ field/ tests/ modules/ field_test_boolean_access_denied/ src/ Hook/ FieldTestBooleanAccessDeniedHooks.php - Implements hook_entity_field_access().
File
-
core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 2145
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();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.