Last active
October 25, 2019 16:44
-
-
Save csymlstd/39293d17683824ab5660374008d760d5 to your computer and use it in GitHub Desktop.
Drupal 8: allow users to filter custom entities on the json api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Related to SA-CONTRIB-2018-081 | |
// https://www.drupal.org/node/3036792 | |
function mymodule_jsonapi_asset_filter_access(\Drupal\Core\Entity\EntityTypeInterface $entity_type, \Drupal\Core\Session\AccountInterface $account) { | |
return ([ | |
JSONAPI_FILTER_AMONG_ALL => AccessResult::allowedIfHasPermission($account, 'administer asset entities'), | |
JSONAPI_FILTER_AMONG_PUBLISHED => AccessResult::allowedIfHasPermission($account, 'view published asset entities'), | |
JSONAPI_FILTER_AMONG_OWN => AccessResult::allowedIfHasPermissions($account, ['view published asset entities', 'view published asset entities'], 'AND'), | |
]); | |
} | |
function mymodule_jsonapi_asset_field_filter_access(\Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account) { | |
return AccessResult::neutral(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment