function administerusersbyrole_entity_field_access in Administer Users by Role 8.2
Same name and namespace in other branches
- 8.3 administerusersbyrole.module \administerusersbyrole_entity_field_access()
Implements hook_entity_field_access().
File
- ./
administerusersbyrole.module, line 96
Code
function administerusersbyrole_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemList $items = NULL) {
if ($field_definition
->getTargetEntityTypeId() != 'user') {
return AccessResult::neutral();
}
$fields = array(
'name',
'status',
'mail',
);
if ($operation == 'view') {
array_push($fields, 'roles', 'access');
}
if (!in_array($field_definition
->getName(), $fields)) {
return AccessResult::neutral();
}
if (is_null($items)) {
if ($operation == 'view') {
// No field item list is passed. This can be used to control whether to hide/show the whole column in views.
// Hence allow if 'access users overview'.
return AccessResult::allowedIfHasPermission($account, 'access users overview');
}
return AccessResult::neutral();
}
return administerusersbyrole_user_access($items
->getEntity(), 'update', $account);
}