function JsonTestFieldFilterAccessHooks::jsonapiEntityFieldFilterAccess

Implements hook_jsonapi_entity_field_filter_access().

Attributes

#[Hook('jsonapi_entity_field_filter_access')]

File

core/modules/jsonapi/tests/modules/jsonapi_test_field_filter_access/src/Hook/JsonTestFieldFilterAccessHooks.php, line 21

Class

JsonTestFieldFilterAccessHooks
Hook implementations for jsonapi_test_field_filter_access.

Namespace

Drupal\jsonapi_test_field_filter_access\Hook

Code

public function jsonapiEntityFieldFilterAccess(FieldDefinitionInterface $field_definition, AccountInterface $account) : AccessResultInterface {
  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.