You are here

protected function FieldResolver::getFieldAccess in JSON:API 8

Same name and namespace in other branches
  1. 8.2 src/Context/FieldResolver.php \Drupal\jsonapi\Context\FieldResolver::getFieldAccess()

Gets the field access result for the 'view' operation.

Parameters

\Drupal\jsonapi\ResourceType\ResourceType $resource_type: The JSON:API resource type on which the field exists.

string $internal_field_name: The field name for which access should be checked.

Return value

\Drupal\Core\Access\AccessResultInterface The 'view' access result.

1 call to FieldResolver::getFieldAccess()
FieldResolver::resolveInternalEntityQueryPath in src/Context/FieldResolver.php
Resolves external field expressions into entity query compatible paths.

File

src/Context/FieldResolver.php, line 654

Class

FieldResolver
A service that evaluates external path expressions against Drupal fields.

Namespace

Drupal\jsonapi\Context

Code

protected function getFieldAccess(ResourceType $resource_type, $internal_field_name) {
  $definitions = $this->fieldManager
    ->getFieldDefinitions($resource_type
    ->getEntityTypeId(), $resource_type
    ->getBundle());
  assert(isset($definitions[$internal_field_name]), 'The field name should have already been validated.');
  $field_definition = $definitions[$internal_field_name];
  $filter_access_results = $this->moduleHandler
    ->invokeAll('jsonapi_entity_field_filter_access', [
    $field_definition,
    \Drupal::currentUser(),
  ]);
  $filter_access_result = array_reduce($filter_access_results, function (AccessResultInterface $combined_result, AccessResultInterface $result) {
    return $combined_result
      ->orIf($result);
  }, AccessResult::neutral());
  if (!$filter_access_result
    ->isNeutral()) {
    return $filter_access_result;
  }
  $entity_access_control_handler = $this->entityTypeManager
    ->getAccessControlHandler($resource_type
    ->getEntityTypeId());
  $field_access = $entity_access_control_handler
    ->fieldAccess('view', $field_definition, NULL, NULL, TRUE);
  return $filter_access_result
    ->orIf($field_access);
}