function jsonapi_test_field_filter_access_jsonapi_entity_field_filter_access

Same name in other branches
  1. 9 core/modules/jsonapi/tests/modules/jsonapi_test_field_filter_access/jsonapi_test_field_filter_access.module \jsonapi_test_field_filter_access_jsonapi_entity_field_filter_access()
  2. 10 core/modules/jsonapi/tests/modules/jsonapi_test_field_filter_access/jsonapi_test_field_filter_access.module \jsonapi_test_field_filter_access_jsonapi_entity_field_filter_access()
  3. 11.x core/modules/jsonapi/tests/modules/jsonapi_test_field_filter_access/jsonapi_test_field_filter_access.module \jsonapi_test_field_filter_access_jsonapi_entity_field_filter_access()

Implements hook_jsonapi_entity_field_field_access().

File

core/modules/jsonapi/tests/modules/jsonapi_test_field_filter_access/jsonapi_test_field_filter_access.module, line 15

Code

function jsonapi_test_field_filter_access_jsonapi_entity_field_filter_access(FieldDefinitionInterface $field_definition, AccountInterface $account) {
    if ($field_definition->getName() === 'spotlight') {
        return AccessResult::forbiddenIf(!$account->hasPermission('filter by spotlight field'))
            ->cachePerPermissions();
    }
    if ($field_definition->getName() === 'field_test_text') {
        return AccessResult::allowedIf($field_definition->getTargetEntityTypeId() === 'entity_test_with_bundle');
    }
    return AccessResult::neutral();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.