public function FieldPermissionsService::getFieldAccess in Field Permissions 8
Same name and namespace in other branches
- 8.2 src/FieldPermissionsService.php \Drupal\field_permissions\FieldPermissionsService::getFieldAccess()
Get access for field by operations and account permisisons.
Parameters
string $operation: String operation on field.
\Drupal\Core\Field\FieldItemListInterface $items: The entity field object on which to check access.
\Drupal\Core\Session\AccountInterface $account: Account to get permissions.
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: Fields to get permissions.
Overrides FieldPermissionsServiceInterface::getFieldAccess
File
- src/
FieldPermissionsService.php, line 162
Class
- FieldPermissionsService
- The field permission service.
Namespace
Drupal\field_permissionsCode
public function getFieldAccess($operation, FieldItemListInterface $items, 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());
return $plugin
->hasFieldAccess($operation, $items
->getEntity(), $account);
}