function hook_entity_field_access in Zircon Profile 8.0
Same name and namespace in other branches
- 8 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\Access\AccessibleInterface::access() 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.
Related topics
4 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.
- entity_test_entity_field_access in core/
modules/ system/ tests/ modules/ entity_test/ entity_test.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()
- views_entity_test_entity_field_access in core/
modules/ views/ tests/ modules/ views_entity_test/ views_entity_test.module - Implements hook_entity_field_access().
1 invocation of hook_entity_field_access()
- EntityAccessControlHandler::fieldAccess in core/
lib/ Drupal/ Core/ Entity/ EntityAccessControlHandler.php - Checks access to an operation on a given entity field.
File
- core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 1874 - 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();
}