You are here

function field_test_entity_field_access in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/tests/modules/field_test/field_test.field.inc \field_test_entity_field_access()

Implements hook_entity_field_access().

File

core/modules/field/tests/modules/field_test/field_test.field.inc, line 43
Defines a field type and its formatters and widgets.

Code

function field_test_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
  if ($field_definition
    ->getName() == "field_no_{$operation}_access") {
    return AccessResult::forbidden();
  }

  // Only grant view access to test_view_field fields when the user has
  // 'view test_view_field content' permission.
  if ($field_definition
    ->getName() == 'test_view_field' && $operation == 'view') {
    return AccessResult::forbiddenIf(!$account
      ->hasPermission('view test_view_field content'))
      ->cachePerPermissions();
  }
  return AccessResult::allowed();
}