function workflow_fields_field_access in Workflow Fields 7
Same name and namespace in other branches
- 6 workflow_fields.module \workflow_fields_field_access()
Implements hook_field_access().
File
- ./
workflow_fields.module, line 587 - This module adds to workflow.module the ability to specify, for each state, which node fields should be visible and/or editable. It is a useful feature when workflows demand that certain information be hidden or read-only to certain roles.
Code
function workflow_fields_field_access($op, $field, $entity_type, $node, $account) {
if ($entity_type == 'node' || !$node) {
$sid = NULL;
$workflow_fields = array(
'',
);
// Workflow 2+
if (function_exists('_workflow_info_fields')) {
$workflow_fields = _workflow_info_fields($node, $entity_type);
if (0 === count($workflow_fields)) {
return TRUE;
}
}
// If there is one workflow that gives access to the field, access is granted
foreach ($workflow_fields as $workflow_field_name => $workflow_field_info) {
$sid = workflow_node_current_state($node, 'node', $workflow_field_name);
if (FALSE === $sid) {
$type_map = workflow_get_workflow_type_map_by_type($node->type);
if (!$type_map) {
return;
}
// Workflow 1.x
if (function_exists('workflow_get_creation_state_by_wid')) {
$sid = workflow_get_creation_state_by_wid($type_map->wid);
}
else {
$workflow = workflow_load($type_map->wid);
$sid = $workflow
->getCreationSid();
}
}
// Check for visible/editable flags.
list($visibles, $editables) = _workflow_fields_compute_permissions($sid, $node->type, $node, $op);
if (isset($visibles[$field['field_name']])) {
$is_accessible = $op == 'view' ? $visibles[$field['field_name']] : $visibles[$field['field_name']] && $editables[$field['field_name']];
if ($is_accessible) {
return TRUE;
}
}
}
return FALSE;
}
else {
return TRUE;
}
}