function field_permission_example_entity_test_access

Same name and namespace in other branches
  1. 4.0.x modules/field_permission_example/field_permission_example.module \field_permission_example_entity_test_access()

Implements hook_ENTITY_TYPE_access().

Note: this routine is added so we can more easily test our access code. Core defines an entity_test entity that is used for testing fields in core. We add this routine to make the entity_test entity editable by our tests.

Related topics

File

modules/field_permission_example/field_permission_example.module, line 163

Code

function field_permission_example_entity_test_access(EntityInterface $entity, $operation, AccountInterface $account, $langcode) {
  if ($operation == 'edit') {
    $perms = [
      'administer the fieldnote field',
      'edit any fieldnote',
      'edit own fieldnote',
    ];
    foreach ($perms as $perm) {
      if ($account->hasPermission($perm)) {
        return AccessResult::allowed();
      }
    }
  }
  return AccessResult::neutral();
}