You are here

content_permissions.module in Content Construction Kit (CCK) 6

File

modules/content_permissions/content_permissions.module
View source
<?php

/**
 *  Implementation of hook_perm().
 */
function content_permissions_perm() {
  foreach (content_fields() as $field) {
    $perms[] = 'edit ' . $field['field_name'];
    $perms[] = 'view ' . $field['field_name'];
  }
  return $perms;
}

/**
 *  Implementation of hook_form_alter(). Remove inaccessible fields from node display.
 */
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);
      }
    }
  }
}

/**
 *  Implementation of hook_nodeapi(). Remove inaccessible fields from node display.
 */
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);
      }
    }
  }
}

/**
 *  The default field access callback. Remove inaccessible fields from Views.
 * 
 * @see content_views_field_views_data(). 
 */
function content_views_access_callback($field) {
  return user_access('view ' . $field['field_name']);
}

Functions

Namesort descending Description
content_permissions_form_alter Implementation of hook_form_alter(). Remove inaccessible fields from node display.
content_permissions_nodeapi Implementation of hook_nodeapi(). Remove inaccessible fields from node display.
content_permissions_perm Implementation of hook_perm().
content_views_access_callback The default field access callback. Remove inaccessible fields from Views.