materio-d9/web/modules/custom/materio_jsonapi/materio_jsonapi.module

23 lines
892 B
PHP
Raw Permalink Normal View History

2019-05-16 18:01:00 +02:00
<?php
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
2019-05-17 17:16:05 +02:00
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
2019-05-16 18:01:00 +02:00
/**
2019-05-17 17:16:05 +02:00
* Implements hook_entity_field_access().
2019-05-16 18:01:00 +02:00
*/
2019-05-17 17:16:05 +02:00
function materio_jsonapi_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
if ($field_definition->getName() == 'roles' && $operation == 'view') {
$user = $items->getEntity();
if($account->id() == $user->id() && !$user->hasPermission('materio_jsonapi roles')){
return AccessResult::allowedIfHasPermission($account, 'materio_jsonapi ownroles');
}
return AccessResult::allowedIfHasPermission($account, 'materio_jsonapi roles');
// return AccessResult::allowed();
2019-05-16 18:01:00 +02:00
}
return AccessResult::neutral();
}