public function FieldPermissionsService::hasFieldViewAccessForEveryEntity in Field Permissions 8.2
Same name and namespace in other branches
- 8 src/FieldPermissionsService.php \Drupal\field_permissions\FieldPermissionsService::hasFieldViewAccessForEveryEntity()
Determines if the given account may view the field, regardless of entity.
This should only return TRUE if
$this
->getFieldAccess('view', $items, $account, $field_definition);
returns TRUE for all possible values of $items.
@todo Move this to an interface: either FieldPermissionsServiceInterface or a new one.
Parameters
\Drupal\Core\Session\AccountInterface $account: Account for which to check access.
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: Field for which to check access.
Return value
bool The access result.
File
- src/
FieldPermissionsService.php, line 197
Class
- FieldPermissionsService
- The field permission service.
Namespace
Drupal\field_permissionsCode
public function hasFieldViewAccessForEveryEntity(AccountInterface $account, FieldDefinitionInterface $field_definition) {
$permission_type = $this
->fieldGetPermissionType($field_definition
->getFieldStorageDefinition());
if (in_array('administrator', $account
->getRoles()) || $permission_type == FieldPermissionTypeInterface::ACCESS_PUBLIC) {
return TRUE;
}
// Field add to comment entity.
if (static::isCommentField($field_definition)) {
return TRUE;
}
// Pass access control to the plugin.
$plugin = $this->permissionTypeManager
->createInstance($permission_type, [], $field_definition
->getFieldStorageDefinition());
if ($plugin instanceof Base) {
return $plugin
->hasFieldViewAccessForEveryEntity($account);
}
else {
return FALSE;
}
}