jsonapi_test_field_filter_access.module

Same filename in other branches
  1. 9 core/modules/jsonapi/tests/modules/jsonapi_test_field_filter_access/jsonapi_test_field_filter_access.module
  2. 10 core/modules/jsonapi/tests/modules/jsonapi_test_field_filter_access/jsonapi_test_field_filter_access.module
  3. 11.x core/modules/jsonapi/tests/modules/jsonapi_test_field_filter_access/jsonapi_test_field_filter_access.module

Contains hook implementations for testing the JSON:API module.

File

core/modules/jsonapi/tests/modules/jsonapi_test_field_filter_access/jsonapi_test_field_filter_access.module

View source
<?php


/**
 * @file
 * Contains hook implementations for testing the JSON:API module.
 */
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Implements hook_jsonapi_entity_field_field_access().
 */
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();
}

Functions

Title Deprecated Summary
jsonapi_test_field_filter_access_jsonapi_entity_field_filter_access Implements hook_jsonapi_entity_field_field_access().

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