0
votes

Im looking for a way to hide a cck field for every one except for one specific role.

I know that there is a module, Content Permission module, that takes good care of this. But I have taken over a very big site with many content types, with lots of related cck fields being defined. So installing Content Permission module is not a good idea because of the great amount of settings it would require.

It's a drupal 6 installation.

2

2 Answers

0
votes

You may use hook_nodeapi in a custom module:

/**
 * Implements hook_nodeapi().
 */
function yourmodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'view':
      if (! user_access('show restricted content')) {
        unset ($node->content['field_restrictedcontent']);
      }
      break;
  }
}

/**
 * Implements hook_perm().
 */
function yourmodule_perm () {
  return array(
    'show restricted content',
  );
}

Nevertheless, be aware that this is somewhat a hack: I think you should reconsider using Content Permission module for your site, and make the effort needed to configure it for your node types. It's a one time job and it may protect you from compatibilities issues with other modules in your site.

0
votes

You need to use any of the permissions module and reconfigure each of those fields in question. With code, you have to check user roles for each of those fields!