? cck_teasers.patch
? t.patch
Index: content.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.install,v
retrieving revision 1.14.2.6
diff -u -p -r1.14.2.6 content.install
--- content.install	7 Jan 2007 00:06:36 -0000	1.14.2.6
+++ content.install	11 Jan 2007 08:59:32 -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)
       ) /*!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)
       )");
@@ -285,3 +287,24 @@ function content_update_1001() {
 
   return $ret;
 }
+
+/**
+ * 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':
+      // TODO : why not db_add_column ?
+      $ret[] = update_sql("ALTER TABLE {node_field_instance} ADD COLUMN display_settings mediumtext NOT NULL");
+      break;
+  }
+
+  return $ret;
+}
Index: content.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.module,v
retrieving revision 1.90.2.25
diff -u -p -r1.90.2.25 content.module
--- content.module	9 Jan 2007 14:54:10 -0000	1.90.2.25
+++ content.module	11 Jan 2007 08:59:33 -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(
@@ -243,7 +252,7 @@ function content_view(&$node, $teaser = 
   if ($node->in_preview) {
     _content_widget_invoke('process form values', $node);
   }
-  $content = _content_field_invoke('view', $node, $teaser, $page);
+  $content = _content_field_view($node, $teaser, $page);
   $node->content = array_merge((array) $node->content, $content);
 }
 
@@ -514,6 +523,44 @@ function _content_field_invoke($op, &$no
 }
 
 /**
+ * Invoke a field hook.
+ *
+ * For each operation, both this function and _content_field_invoke_default() are
+ * called so that the default database handling can occur.
+ */
+function _content_field_view(&$node, $teaser = NULL, $page = NULL) {
+  $type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);
+  $type = content_types($type_name);
+  $field_types = _content_field_types();
+
+  $return = array();
+  if (count($type['fields'])) {
+    foreach ($type['fields'] as $field) {
+      $node_field = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();
+
+       // Determine the correct formatter for this instance.
+      $style = $page ? 'page' : ($teaser ? 'teaser' : 'full');
+      if ($field['display_settings'][$style]['enabled']) {
+        $formatter = $field['display_settings'][$style]['formatter'] ? $field['display_settings'][$style]['formatter'] : 'default';
+        $label = $field['display_settings']['label']['enabled'] ? $field['display_settings']['label']['format'] : 'hidden';
+  
+        foreach ($node_field as $delta => $item) {
+          $items[$delta]['view'] = content_format($field, $item, $formatter, $node);
+        }
+        $result = theme('field', $node, $field, $items, $style, $label);
+  
+        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);
+        }
+      }
+    }
+  }
+  return $return;
+}
+
+/**
  * Invoke content.module's version of a field hook.
  */
 function _content_field_invoke_default($op, &$node, $teaser = NULL, $page = NULL) {
@@ -725,7 +772,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);
@@ -742,6 +789,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;
@@ -902,26 +950,35 @@ function content_format($field, $item, $
  *   The actual items to theme. This will be a linear array, each element of
  *   which has a "view" property which contains the filtered, formatted contents
  *   of the item.
- * @param $teaser
- *   Whether the node is being displayed as a teaser or full version.
- * @param $page
- *   Whether the node is being displayed as a full web page.
+ * @param $context
+ *   The context of the field: 'teaser', 'full', and 'page' are currently used.
+ * @param $label_display
+ *   The format to display the label in.
  *
  * @return
  *   An HTML string containing the fully themed field.
  */
-function theme_field(&$node, &$field, &$items, $teaser, $page) {
+function theme_field(&$node, &$field, &$items, $context = 'full', $label_display = 'inline') {
+  switch ($label_display) {
+    case 'header':
+      $header = '<h3 class="field-label">'. $field['widget']['label'] .'</h3>';
+      break;
+    case 'inline':
+      $inline = '<strong>'. $field['widget']['label'] .':</strong> ';
+      break;
+  }
+
   $items_output = '';
   foreach ($items as $item) {
     if (!empty($item['view']) || $item['view'] === "0") {
-      $items_output .= '<div class="field-item">'. $item['view'] .'</div>';
+      $items_output .= '<div class="field-item">'. $inline . $item['view'] .'</div>';
     }
   }
-  $output = '';
+
   if (!empty($items_output)) {
     $output .= '<div class="field field-type-'. strtr($field['type'], '_', '-') .' field-'. strtr($field['field_name'], '_', '-') .'">';
-    $output .= '<h3 class="field-label">'. $field['widget']['label'] .'</h3>';
-    $output .= '<div class="field-items">'. $items_output .'</div>';
+    $output .= $header;
+    $output .= !empty($items_output) ? '<div class="field-items">'. $items_output .'</div>': '';
     $output .= '</div>';
   }
   return $output;
Index: content_admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content_admin.inc,v
retrieving revision 1.28.2.16
diff -u -p -r1.28.2.16 content_admin.inc
--- content_admin.inc	10 Jan 2007 12:52:17 -0000	1.28.2.16
+++ content_admin.inc	11 Jan 2007 08:59:34 -0000
@@ -786,6 +786,143 @@ 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'));
+  foreach(_content_admin_display_contexts() 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) {
+    $display_settings = array();
+    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'];
+
+  foreach($field_types[$field['type']]['formatters'] as $name => $formatter_info) {
+    $options[$name] = $formatter_info['label'];
+  }
+
+  $label_options = array(
+    'inline' => t('Inline'),
+    'header' => t('Header'),
+  );
+
+  $row = array();
+  $row['type_label']  = array('#value' => $field['widget']['label']);
+  $row['type']        = array('#value' => $field_types[$field['type']]['label']);
+
+  $row['label'] = array(
+    '#prefix' => '<div class="container-inline">',
+    '#suffix' => '</div>',
+  );
+  $row['label']['enabled'] = array(
+    '#type' => 'checkbox',
+    '#default_value' => isset($defaults['label']['enabled']) ? $defaults['label']['enabled'] : 1,
+  );
+  $row['label']['format'] = array(
+    '#type' => 'select',
+    '#options' => $label_options,
+    '#default_value' => isset($defaults['label']['format']) ? $defaults['label']['format'] : NULL,
+  );
+
+  foreach(_content_admin_display_contexts() as $key => $title) {
+    $row[$key] = array(
+      '#prefix' => '<div class="container-inline">',
+      '#suffix' => '</div>',
+    );
+    $row[$key]['enabled'] = array(
+      '#type' => 'checkbox',
+      '#default_value' => isset($defaults[$key]['enabled']) ? $defaults[$key]['enabled'] : 1,
+    );
+    $row[$key]['format'] = array(
+      '#type' => 'select',
+      '#options' => $options,
+      '#default_value' => isset($defaults[$key]['format']) ? $defaults[$key]['format'] : NULL,
+    );
+  }
+  return $row;
+}
+
+function _content_admin_display_contexts() {
+  return array(
+    'teaser' => t('Teaser'),
+    'full' => t('Full'),
+    'page' => t('Page'),
+  );
+}
+
 
 /**
  * Perform adds, alters, and drops as needed to synchronize the database with
