function FieldResolver::getFieldAccess

Same name in other branches
  1. 9 core/modules/jsonapi/src/Context/FieldResolver.php \Drupal\jsonapi\Context\FieldResolver::getFieldAccess()
  2. 8.9.x core/modules/jsonapi/src/Context/FieldResolver.php \Drupal\jsonapi\Context\FieldResolver::getFieldAccess()
  3. 10 core/modules/jsonapi/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 core/modules/jsonapi/src/Context/FieldResolver.php
Resolves external field expressions into entity query compatible paths.

File

core/modules/jsonapi/src/Context/FieldResolver.php, line 754

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,
        $this->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);
}

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