Alters the default access behaviour for a given field.
Use this hook to override access grants from another module. Note that the original default access flag is masked under the ':default' key.
array $grants: An array of grants gathered by hook_entity_field_access(). The array is keyed by the module that defines the field's access control; the values are grant responses for each module (Boolean or NULL).
array $context: Context array on the performed operation with the following keys:
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
function hook_entity_field_access_alter(array &$grants, array $context) {
$field = $context['field'];
if ($field
->getName() == 'field_of_interest' && $grants['node'] === FALSE) {
// Override node module's restriction to no opinion. We don't want to
// provide our own access hook, we only want to take out node module's part
// in the access handling of this field. We also don't want to switch node
// module's grant to TRUE, because the grants of other modules should still
// decide on their own if this field is accessible or not.
$grants['node'] = NULL;
}
}