Index: content.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.install,v
retrieving revision 1.14.2.3
diff -u -p -r1.14.2.3 content.install
--- content.install	5 Jan 2007 11:57:46 -0000	1.14.2.3
+++ content.install	6 Jan 2007 09:13:37 -0000
@@ -28,6 +28,7 @@ function content_install() {
         label varchar(255) NOT NULL default '',
         widget_type varchar(32) NOT NULL default '',
         widget_settings mediumtext NOT NULL,
+        display_settings mediumtext NOT NULL,
         description mediumtext NOT NULL,
         PRIMARY KEY  (field_name,type_name)
       ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
@@ -50,6 +51,7 @@ function content_install() {
         label varchar(255) NOT NULL default '',
         widget_type varchar(32) NOT NULL default '',
         widget_settings text NOT NULL,
+        display_settings text NOT NULL,
         description text NOT NULL,
         PRIMARY KEY  (field_name,type_name)
       )");
@@ -307,4 +309,24 @@ function content_update_1001() {
   }
 
   return $ret;
-}
\ No newline at end of file
+}
+
+/**
+ * Add information about where data is stored.
+ */
+function content_update_1002() {
+  $ret = array();
+
+  switch ($GLOBALS['db_type']) {
+    case 'pgsql':
+      db_add_column($ret, 'node_field_instance', 'display_settings', 'text', array('not null' => TRUE, 'default' => ''));
+      break;
+
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {node_field_instance} ADD COLUMN display_settings mediumtext NOT NULL default ''");
+      break;
+  }
+
+  return $ret;
+}
Index: content.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.module,v
retrieving revision 1.90.2.14
diff -u -p -r1.90.2.14 content.module
--- content.module	5 Jan 2007 11:57:46 -0000	1.90.2.14
+++ content.module	6 Jan 2007 09:13:37 -0000
@@ -85,6 +85,15 @@ function content_menu($may_cache) {
           'type' => MENU_LOCAL_TASK,
           'weight' => 2,
         );
+        $items[] = array(
+          'path' => 'admin/content/types/'. $content_type['url_str'] .'/display',
+          'title' => t('Display'),
+          'callback' => 'drupal_get_form',
+          'access' => $access,
+          'callback arguments' => array('content_admin_field_display_form', $content_type['type']),
+          'type' => MENU_LOCAL_TASK,
+          'weight' => 3,
+        );
 
         if (arg(4) == 'fields' && arg(5) && isset($content_type['fields'][arg(5)])) {
           $items[] = array(
@@ -487,19 +496,33 @@ function _content_field_invoke($op, &$no
       $module = $field_types[$field['type']]['module'];
       $function = $module .'_field';
       if (function_exists($function)) {
-        $result = $function($op, $node, $field, $node_field, $teaser, $page);
         if ($op == 'view') {
-          if (!is_array($result)) $result = array($result);
-          $return[$field['field_name']] = array('#weight' => $field['widget']['weight']);
-          foreach ($result as $delta => $value) {
-            $return[$field['field_name']][$delta] = array('#value' => $value);
+          // Determine the correct formatter for this instance.
+          $style = $page ? 'page' : ($teaser ? 'teaser' : 'full');
+          $formatter = $field['display_settings'][$style];
+
+          if ($formatter != 'none') {
+            $result = $function($op, $node, $field, $node_field, $teaser, $page, $formatter);
+            if (!is_array($result)) {
+              $result = array($result);
+            }
+            $return[$field['field_name']] = array('#weight' => $field['widget']['weight']);
+            foreach ($result as $delta => $value) {
+              $return[$field['field_name']][$delta] = array('#value' => $value);
+            }
+          }
+          else {
+            $return = array();
           }
         }
-        elseif (is_array($result)) {
-          $return = array_merge($return, $result);
-        }
-        else if (isset($result)) {
-          $return[] = $result;
+        else {
+          $result = $function($op, $node, $field, $node_field, $teaser, $page);
+          if (is_array($result)) {
+            $return = array_merge($return, $result);
+          }
+          else {
+            $return[] = $result;
+          }
         }
       }
       // test for values in $node_field in case modules added items on insert
@@ -718,7 +741,7 @@ function _content_type_info($reset = FAL
         $type['url_str'] = str_replace('_', '-', $type['type']);
         $type['fields'] = array();
         $type['table'] = _content_tablename($type['type']);
-        $field_result = db_query("SELECT nfi.field_name, nfi.weight, nfi.label, nfi.widget_type, nfi.widget_settings, nfi.description FROM {node_field_instance} nfi WHERE nfi.type_name = '%s' ORDER BY nfi.weight ASC, nfi.label ASC", $type['type']);
+        $field_result = db_query("SELECT nfi.field_name, nfi.weight, nfi.label, nfi.widget_type, nfi.widget_settings, nfi.display_settings, nfi.description FROM {node_field_instance} nfi WHERE nfi.type_name = '%s' ORDER BY nfi.weight ASC, nfi.label ASC", $type['type']);
         while ($field = db_fetch_array($field_result)) {
           // Overwrite global field information with specific information
           $field = array_merge($info['fields'][$field['field_name']], $field);
@@ -735,6 +758,7 @@ function _content_type_info($reset = FAL
           $field['widget']['description'] = $field['description'];
           unset($field['description']);
           $field['type_name'] = $type['type'];
+          $field['display_settings'] = $field['display_settings'] ? unserialize($field['display_settings']) : array();
           $type['fields'][$field['field_name']] = $field;
         }
         $info['content types'][$type['type']] = $type;
Index: content_admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content_admin.inc,v
retrieving revision 1.28.2.11
diff -u -p -r1.28.2.11 content_admin.inc
--- content_admin.inc	5 Jan 2007 12:37:14 -0000	1.28.2.11
+++ content_admin.inc	6 Jan 2007 09:13:38 -0000
@@ -786,6 +786,119 @@ function _content_admin_field_submit($fo
   return 'admin/content/types/'. $type['url_str'] .'/fields';
 }
 
+function content_admin_field_display_form($type_name) {
+  $form = array();
+
+  $type = content_types($type_name);
+  $field_types = _content_field_types();
+
+  // Create a dummy node and form and call hook_form_alter()
+  // to produce an array of fields and weights added to the node by all modules.
+  $dummy_node = new StdClass();
+  $dummy_node->type = $type['type'];
+  $dummy_form_id = $type['type'] .'_node_form';
+  $dummy_form = node_form($dummy_node);
+  foreach (module_implements('form_alter') as $module) {
+    $function = $module .'_form_alter';
+    $function($dummy_form_id, $dummy_form);
+  }
+  
+  if (!$type['fields']) {
+    drupal_set_message(t('There are no fields configured for this content type.'));
+  }
+
+  if (!$type['fields'] && !$form['#groups']) {
+    return $form;
+  }
+
+  // Iterate through the dummy form and add top-level fields and weights to a table.
+  // Construct the table values in an array '#table' that FAPI will ignore, keyed on the item's weight.
+  // Create separate form elements for each weight and group value and put a placeholder for each in #table.
+
+  $form['#tree'] = TRUE;
+  foreach ($dummy_form as $key => $value) {
+    // Limiting weight to < 10 will keep workflow and submit elements from being added to the overview table.
+    // They're outside the weight range allowed for CCK fields, so won't interfere with field placement.
+    if (is_array($value) && (isset($value['#weight']) || $key == 'body_filter') && $value['#weight'] <= 10) {
+      if (substr($key, 0, 6) == 'field_') {
+        $form['fields'][$key] = _content_admin_build_display_row($type['fields'][$key], $field_types);
+      }
+    }
+  }
+
+  $form['type_name'] = array('#type' => 'hidden', '#value' => $type['type']);
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
+
+  return $form;
+}
+
+function theme_content_admin_field_display_form($form) {
+  $header = array(t('Field'), t('Type'), t('Label visiblity'));
+  foreach(_content_admin_display_styles() as $key => $title) {
+    $header[] = $title;
+  }
+  $rows = array();
+
+  foreach(element_children($form['fields']) as $field) {
+    $row = array();
+    foreach(element_children($form['fields'][$field]) as $key) {
+      $row[] = drupal_render($form['fields'][$field][$key]);
+    }
+    $rows[] = $row;
+  }
+
+  $output  = theme('table', $header, $rows, array('class' => 'content-field-overview'));
+  $output .= drupal_render($form);
+  return $output;
+}
+
+function content_admin_field_display_form_submit($form_id, $form_values) {
+  $type = $form_values['type_name'];
+  foreach($form_values['fields'] as $fieldname => $fieldvalues) {
+    foreach($fieldvalues as $key => $value) {
+      $display_settings[$key] = $value;
+    }
+    db_query("UPDATE {node_field_instance} SET display_settings = '%s' WHERE type_name = '%s' AND field_name = '%s'",
+      serialize($display_settings), $form_values['type_name'], $fieldname);
+  }
+  
+  content_clear_type_cache();
+}
+
+function _content_admin_build_display_row($field, $field_types) {
+  $defaults = $field['display_settings'];
+
+  $options['default'] = t('Default');
+  $options['none'] = t('Hide field');
+  foreach($field_types[$field['type']]['formatters'] as $name => $formatter_info) {
+    $options[$name] = $formatter_info['label'];
+  }
+
+  $label_options = array(
+    'never' =>   t('Never'),
+    'always' =>  t('Always'),
+    'default' => t('When populated'),
+  );
+
+  $row = array();
+  $row['type_label']  = array('#value' => $field['widget']['label']);
+  $row['type']        = array('#value' => $field_types[$field['type']]['label']);
+
+  $row['label']       = array('#type' => 'select', '#options' => $label_options, '#default_value' => isset($defaults['label']) ? $defaults['label'] : 'default');
+  
+  foreach(_content_admin_display_styles() as $key => $title) {
+    $row[$key] = array('#type' => 'select', '#options' => $options, '#default_value' => isset($defaults[$key]) ? $defaults[$key] : 'default');
+  }
+  return $row;
+}
+
+function _content_admin_display_styles() {
+  return array(
+    'teaser' => t('Teaser'),
+    'full' => t('Full'),
+    'page' => t('Page'),
+  );
+}
 
 /**
  * Perform adds, alters, and drops as needed to synchronize the database with
Index: nodereference.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/nodereference.module,v
retrieving revision 1.39.2.2
diff -u -p -r1.39.2.2 nodereference.module
--- nodereference.module	1 Jan 2007 16:39:18 -0000	1.39.2.2
+++ nodereference.module	6 Jan 2007 09:13:39 -0000
@@ -109,11 +109,11 @@ function nodereference_field_settings($o
 /**
  * Implementation of hook_field().
  */
-function nodereference_field($op, &$node, $field, &$items, $teaser, $page) {
+function nodereference_field($op, &$node, $field, &$items, $teaser, $page, $default = 'default') {
   switch ($op) {
     case 'view':
       foreach ($items as $delta => $item) {
-        $items[$delta]['view'] = content_format($field, $item, 'default', $node);
+        $items[$delta]['view'] = content_format($field, $item, $default, $node);
       }
       return theme('field', $node, $field, $items, $teaser, $page);
   }
Index: number.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/number.module,v
retrieving revision 1.34.2.4
diff -u -p -r1.34.2.4 number.module
--- number.module	5 Jan 2007 11:57:46 -0000	1.34.2.4
+++ number.module	6 Jan 2007 09:13:39 -0000
@@ -116,11 +116,11 @@ function number_field_settings($op, $fie
 /**
  * Implementation of hook_field().
  */
-function number_field($op, &$node, $field, &$items, $teaser, $page) {
+function number_field($op, &$node, $field, &$items, $teaser, $page, $default = 'default') {
   switch ($op) {
     case 'view':
       foreach ($items as $delta => $item) {
-        $items[$delta]['view'] = content_format($field, $item, 'default', $node);
+        $items[$delta]['view'] = content_format($field, $item, $default, $node);
       }
       return theme('field', $node, $field, $items, $teaser, $page);
 
Index: text.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/text.module,v
retrieving revision 1.41.2.4
diff -u -p -r1.41.2.4 text.module
--- text.module	1 Jan 2007 19:40:29 -0000	1.41.2.4
+++ text.module	6 Jan 2007 09:13:39 -0000
@@ -115,11 +115,11 @@ function text_field_settings($op, $field
 /**
  * Implementation of hook_field().
  */
-function text_field($op, &$node, $field, &$items, $teaser, $page) {
+function text_field($op, &$node, $field, &$items, $teaser, $page, $default = 'default') {
   switch ($op) {
     case 'view':
       foreach ($items as $delta => $item) {
-        $items[$delta]['view'] = content_format($field, $item, 'default', $node);
+        $items[$delta]['view'] = content_format($field, $item, $default, $node);
       }
       return theme('field', $node, $field, $items, $teaser, $page);
 
Index: userreference.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/userreference.module,v
retrieving revision 1.30.2.4
diff -u -p -r1.30.2.4 userreference.module
--- userreference.module	1 Jan 2007 16:39:18 -0000	1.30.2.4
+++ userreference.module	6 Jan 2007 09:13:40 -0000
@@ -66,11 +66,11 @@ function userreference_field_settings($o
 /**
  * Implementation of hook_field().
  */
-function userreference_field($op, &$node, $field, &$items, $teaser, $page) {
+function userreference_field($op, &$node, $field, &$items, $teaser, $page, $default = 'default') {
   switch ($op) {
     case 'view':
       foreach ($items as $delta => $item) {
-        $items[$delta]['view'] = content_format($field, $item, 'default', $node);
+        $items[$delta]['view'] = content_format($field, $item, $default, $node);
       }
       return theme('field', $node, $field, $items, $teaser, $page);
   }
