function hook_jsonapi_ENTITY_TYPE_filter_access

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/jsonapi.api.php \hook_jsonapi_ENTITY_TYPE_filter_access()
  2. 8.9.x core/modules/jsonapi/jsonapi.api.php \hook_jsonapi_ENTITY_TYPE_filter_access()
  3. 10 core/modules/jsonapi/jsonapi.api.php \hook_jsonapi_ENTITY_TYPE_filter_access()

Controls access to filtering by entity data via JSON:API.

This is the entity-type-specific variant of hook_jsonapi_entity_filter_access(). For implementations with logic that is specific to a single entity type, it is recommended to implement this hook rather than the generic hook_jsonapi_entity_filter_access() hook, which is called for every entity type.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type of the entities to be filtered upon.

\Drupal\Core\Session\AccountInterface $account: The account for which to check access.

Return value

\Drupal\Core\Access\AccessResultInterface[] The array of access results, keyed by subset. See hook_jsonapi_entity_filter_access() for details.

See also

hook_jsonapi_entity_filter_access()

Related topics

12 functions implement hook_jsonapi_ENTITY_TYPE_filter_access()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

jsonapi_jsonapi_block_content_filter_access in core/modules/jsonapi/jsonapi.module
Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'block_content'.
jsonapi_jsonapi_comment_filter_access in core/modules/jsonapi/jsonapi.module
Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'comment'.
jsonapi_jsonapi_entity_filter_access in core/modules/jsonapi/jsonapi.module
Implements hook_jsonapi_entity_filter_access().
jsonapi_jsonapi_entity_test_filter_access in core/modules/jsonapi/jsonapi.module
Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'entity_test'.
jsonapi_jsonapi_file_filter_access in core/modules/jsonapi/jsonapi.module
Implements hook_jsonapi_ENTITY_TYPE_filter_access() for 'file'.

... See full list

File

core/modules/jsonapi/jsonapi.api.php, line 303

Code

function hook_jsonapi_ENTITY_TYPE_filter_access(\Drupal\Core\Entity\EntityTypeInterface $entity_type, \Drupal\Core\Session\AccountInterface $account) {
    return [
        JSONAPI_FILTER_AMONG_ALL => AccessResult::allowedIfHasPermission($account, 'administer llamas'),
        JSONAPI_FILTER_AMONG_PUBLISHED => AccessResult::allowedIfHasPermission($account, 'view all published llamas'),
        JSONAPI_FILTER_AMONG_OWN => AccessResult::allowedIfHasPermissions($account, [
            'view own published llamas',
            'view own unpublished llamas',
        ], 'AND'),
    ];
}

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