class JsonapiTestFieldAccessHooks
Hook implementations for jsonapi_test_field_access.
Hierarchy
- class \Drupal\jsonapi_test_field_access\Hook\JsonapiTestFieldAccessHooks
Expanded class hierarchy of JsonapiTestFieldAccessHooks
File
-
core/
modules/ jsonapi/ tests/ modules/ jsonapi_test_field_access/ src/ Hook/ JsonapiTestFieldAccessHooks.php, line 15
Namespace
Drupal\jsonapi_test_field_access\HookView source
class JsonapiTestFieldAccessHooks {
/**
* Implements hook_entity_field_access().
*/
public function entityFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account) {
// @see \Drupal\Tests\jsonapi\Functional\ResourceTestBase::testRelationships().
if ($field_definition->getName() === 'field_jsonapi_test_entity_ref') {
// Forbid access in all cases.
$permission = "field_jsonapi_test_entity_ref {$operation} access";
$access_result = $account->hasPermission($permission) ? AccessResult::allowed() : AccessResult::forbidden("The '{$permission}' permission is required.");
return $access_result->addCacheContexts([
'user.permissions',
]);
}
// No opinion.
return AccessResult::neutral();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.