content_permissions.module in Content Construction Kit (CCK) 6
File
modules/content_permissions/content_permissions.module
View source
<?php
function content_permissions_perm() {
foreach (content_fields() as $field) {
$perms[] = 'edit ' . $field['field_name'];
$perms[] = 'view ' . $field['field_name'];
}
return $perms;
}
function content_permissions_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
$type = content_types($form['type']['#value']);
foreach ($type['fields'] as $field_name => $field) {
if (isset($form[$field_name])) {
$form[$field_name]['#access'] = user_access('edit ' . $field_name);
}
}
}
}
function content_permissions_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'view') {
$type = content_types($node->type);
foreach ($type['fields'] as $field_name => $field) {
if (isset($node->content[$field_name])) {
$node->content[$field_name]['#access'] = user_access('view ' . $field_name);
}
}
}
}
function content_views_access_callback($field) {
return user_access('view ' . $field['field_name']);
}