function workflow_fields_field_access in Workflow Fields 6
Same name and namespace in other branches
- 7 workflow_fields.module \workflow_fields_field_access()
Implementation of hook_field_access().
File
- ./
workflow_fields.module, line 570 - 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, $account = NULL, $node = NULL) {
if (!$node) {
return TRUE;
}
$node = node_load($node->nid);
// The node object can be a views result object too: not good
$sid = workflow_node_current_state($node);
if (!$sid) {
return TRUE;
}
if (!is_numeric($sid)) {
$sid = db_result(db_query("SELECT sid FROM {workflow_states} ws \n LEFT JOIN {workflow_type_map} wtm ON ws.wid = wtm.wid \n WHERE wtm.type = '%s' AND ws.sysid = %d", $node->type, WORKFLOW_CREATION));
}
// Check for visible/editable flags.
list($visibles, $editables) = _workflow_fields_compute_permissions($sid, $node->type, $node, $op);
if (!isset($visibles[$field['field_name']])) {
return TRUE;
}
return $op == 'view' ? $visibles[$field['field_name']] : $visibles[$field['field_name']] && $editables[$field['field_name']];
}