materio_jsonapi.module 892 B

12345678910111213141516171819202122
  1. <?php
  2. use Drupal\Core\Entity\EntityInterface;
  3. use Drupal\Core\Session\AccountInterface;
  4. use Drupal\Core\Access\AccessResult;
  5. use Drupal\Core\Field\FieldDefinitionInterface;
  6. use Drupal\Core\Field\FieldItemListInterface;
  7. /**
  8. * Implements hook_entity_field_access().
  9. */
  10. function materio_jsonapi_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
  11. if ($field_definition->getName() == 'roles' && $operation == 'view') {
  12. $user = $items->getEntity();
  13. if($account->id() == $user->id() && !$user->hasPermission('materio_jsonapi roles')){
  14. return AccessResult::allowedIfHasPermission($account, 'materio_jsonapi ownroles');
  15. }
  16. return AccessResult::allowedIfHasPermission($account, 'materio_jsonapi roles');
  17. // return AccessResult::allowed();
  18. }
  19. return AccessResult::neutral();
  20. }