? cck_field_perms.patch Index: cck_field_perms.module =================================================================== RCS file: /cvs/drupal/contributions/modules/cck_field_perms/cck_field_perms.module,v retrieving revision 1.3.2.27 diff -u -p -r1.3.2.27 cck_field_perms.module --- cck_field_perms.module 27 Aug 2007 21:25:36 -0000 1.3.2.27 +++ cck_field_perms.module 28 May 2008 23:41:20 -0000 @@ -96,9 +96,17 @@ function cck_field_perms_nodeapi(&$node, /** - * Implemenation of hook form_alter + * Implementation of hook form_alter */ function cck_field_perms_form_alter($form_id, &$form) { + //Alter the permissions page to show cck field labels instead of machine readable cck field names + //Still store permissions by machine readable name + if($form_id == 'user_admin_perm') { + foreach(_cfp_field_perms_name_pair() as $field_name => $field_label) { + $form['permission'][$field_name]['#value'] = $field_label; + } + return; + } if ($form['#id'] != 'node-form') return; // detect if we're editing or creating if ($form['#node']->nid) { @@ -137,18 +145,43 @@ function cck_field_perms_alter_options() /** + * display helper + * retrieve both the human and machine readable form of the permission + * allows cck fields to change labels without losing permission settings + * + * @return array + */ +function _cfp_field_perms_name_pair(){ + $perm_list = array(); + $field_perms = unserialize(variable_get('cfp_values', null)); + if ($field_perms) { + foreach ($field_perms as $type_name => $fields) { + foreach ($fields as $field_name => $value) { + if ($value) { + foreach (cck_field_perms_verbs() as $verb){ + $perm_list[_cfp_content_to_readable($type_name, $field_name, $verb)] + = _cfp_content_to_readable($type_name, $field_name, $verb, False); + } + } + } + } + } + return $perm_list; +} + +/** * perms helper * converts drupal content names to human readable names */ -function _cfp_content_to_readable($content_type, $field_name, $verb) { + +function _cfp_content_to_readable ($content_type, $field_name, $verb, $by_field_name = True) { static $content_types; if (! $content_types) {$content_types = content_types();} - // support fieldgroup content - if (strstr($field_name, "group_")) { + // support fieldgroup content and return the label for display if requested + if ($by_field_name || strstr($field_name, "group_")) { $output = $verb ." ". $content_types[$content_type]['name'] ." ". $field_name; - } - else { + } else { $output = $verb ." ". $content_types[$content_type]['name'] ." ". $content_types[$content_type]['fields'][$field_name]['widget']['label']; } return $output;