Index: content_permissions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/modules/content_permissions/Attic/content_permissions.module,v
retrieving revision 1.5.2.5
diff -u -p -r1.5.2.5 content_permissions.module
--- content_permissions.module	27 Dec 2008 22:22:55 -0000	1.5.2.5
+++ content_permissions.module	20 Feb 2009 21:21:21 -0000
@@ -14,6 +14,33 @@ function content_permissions_perm() {
 }
 
 /**
+ *  Implementation of hook_menu().
+ */
+function content_permissions_menu() {
+  $items['admin/settings/content_permissions'] = array(
+    'title' => 'Content Permissions',
+    'description' => 'Global settings for the behavior of Content Permissions.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('_content_permissions_settings'),
+    'access arguments' => array('administer nodes'),
+  );
+  return $items;
+}
+
+/**
+ *  System settings form for Content Permissions.
+ */
+function _content_permissions_settings() {
+  $form['content_permissions_hide_view_only_when_editing'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('When editing a node form, hide fields that a user only has view access to.'),
+    '#default_value' => variable_get('content_permissions_hide_view_only_when_editing', TRUE),
+    '#description' => t('Check this box to hide fields on the editing form when a user has only view, but not edit access.'),
+  );
+  return system_settings_form($form);
+}
+
+/**
  * Implementation of hook_field_access().
  *
  * @see content_access().
@@ -26,3 +53,57 @@ function content_permissions_field_acces
   }
   return TRUE;
 }
+
+/**
+ *  Implementation of hook_form_alter().
+ *
+ *  When appropriate this hook will change hidden 'value' field elements to
+ *  'markup' elements so that even if edit permission is lacking a field can
+ *  still be viewable on the edit form.
+ */
+function content_permissions_form_alter(&$form, $form_state, $form_id) {
+  // Only attempt to display restricted fields if the system variable for hiding dictates it.
+  if (!variable_get('content_permissions_hide_view_only_when_editing', TRUE)) {
+    if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
+      $append_handler = FALSE;
+      $type_info = content_types($form['type']['#value']);
+      // Loop through all of the fields of a node form.
+      foreach ($type_info['fields'] as $field) {
+        // Check for any fields that do not have edit permission but do have view permission.
+        if (!user_access('edit '. $field['field_name']) && user_access('view '. $field['field_name'])) {
+          // If any fields are altered, add a custom validation handler.
+          $append_handler = TRUE;
+          // Pass the value of the field along in this prefixed field.
+          $form['_content_permission_'. $field['field_name']] = array(
+            '#access' => TRUE,
+            '#type' => 'value',
+            '#value' => $form[$field['field_name']]['#value'],
+          );
+          $node = $form['#node'];
+          content_view($node);
+          // Output the field as it would be rendered on a view page.
+          $form[$field['field_name']] = array(
+            '#type' => 'markup',
+            '#weight' => $field['widget']['weight'],
+            '#value' => drupal_render($node->content[$field['field_name']]),
+          );
+        }
+      }
+      if ($append_handler) {
+        $form['#validate'] = array_merge(array('content_permissions_validate_handler'), $form['#submit']);
+      }
+    }
+  }
+}
+
+/**
+ *  Custom validation handler to move prefixed field values into the proper place in the $form_state array.
+ */
+function content_permissions_validate_handler($form, &$form_state) {
+  foreach ($form_state['values'] as $key => $value) {
+    if (strstr($key, '_content_permission_')) {
+      $form_state['values'][str_replace('_content_permission_', '', $key)] = $value;
+      unset($form_state['values'][$key]);
+    }
+  }
+}
