function hook_entity_field_access

Control access to fields.

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

Parameters

string $operation: The operation to be performed. See \Drupal\Core\TypedData\AccessibleInterface::access() for possible values.

\Drupal\Core\Entity\Field\Type\Field $field: The entity field object on which the operation is to be performed.

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

Return value

bool|NULL TRUE if access should be allowed, FALSE if access should be denied and NULL if the implementation has no opinion.

Related topics

1 function implements 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 drupal/core/modules/system/tests/modules/entity_test/entity_test.module
Implements hook_entity_field_access().
1 invocation of hook_entity_field_access()
Field::access in drupal/core/lib/Drupal/Core/Entity/Field/Type/Field.php
Implements \Drupal\Core\TypedData\AccessibleInterface::access().

File

drupal/core/includes/entity.api.php, line 576
Hooks provided the Entity module.

Code

function hook_entity_field_access($operation, $field, \Drupal\Core\Session\AccountInterface $account) {
  if ($field
    ->getName() == 'field_of_interest' && $operation == 'update') {
    return user_access('update field of interest', $account);
  }
}