function hook_entity_field_access_alter

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.

Parameters

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:

Related topics

1 function implements hook_entity_field_access_alter()

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_alter in drupal/core/modules/system/tests/modules/entity_test/entity_test.module
Implements hook_entity_field_access_alter().

File

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

Code

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;
  }
}