Index: content_panels.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/Attic/content_panels.inc,v
retrieving revision 1.1.2.10
diff -u -r1.1.2.10 content_panels.inc
--- content_panels.inc	23 Mar 2008 16:30:59 -0000	1.1.2.10
+++ content_panels.inc	26 Apr 2008 14:28:06 -0000
@@ -1,14 +1,34 @@
 <?php
 // $Id: content_panels.inc,v 1.1.2.10 2008/03/23 16:30:59 yched Exp $
+/**
+ * Panels 2 interface for CCK fieldgroups and fields.
+ * 
+ * TODO:
+ * 
+ * - Add relevant fieldgroups to each field category instead of the node context.
+ * - Adjust the fields and groups that are displayed for context, when that
+ *   capability is added to Panels.
+ * 
+ */
 
 /**
- * Callback function to supply a list of content types.
+ * Implementation of hook_panels_content_types()
  */
 function content_panels_content_types() {
   $items = array();
+  $items['content'] = array(
+    'title' => t('CCK fields'),
+    'weight' => -10,
+    'single' => FALSE,
+    'content_types' => 'content_admin_content_types_cck_content',
+    'add callback' => 'content_admin_edit_cck_content',
+    'edit callback' => 'content_admin_edit_cck_content',
+    'render callback' => 'content_admin_render_cck_content',
+    'title callback' => 'content_admin_title_content',
+    );
   if (module_exists('fieldgroup')) {
     $items['node_cck_group'] = array(
-      'title' => t('Node CCK Group'),
+      'title' => t('Fieldgroup'),
       'content_types' => 'content_admin_content_types_node_cck_group',
       'single' => TRUE, // only provides a single content type
       'render callback' => 'content_content_node_cck_group',
@@ -20,6 +40,112 @@
   return $items;
 }
 
+function content_admin_content_types_cck_content() {
+  $types = content_types();
+  $field_types = _content_field_types();
+  $items = array();
+
+  foreach ($types as $type_name => $type) {
+    foreach ($type['fields'] as $field_name => $field) {
+      $items[$type_name .':'. $field_name] = array(
+        'title' => $field['widget']['label'],
+        'description' => $field_types[$field['type']]['label'] .': '. $field['field_name'],
+        'icon' => 'icon_node.png',
+        'path' => panels_get_path('content_types/node'),
+        'required context' => new panels_required_context(t('Node'), 'node'),
+        // Position this below the node context category but before any others that follow it.
+        'category' => array(t('Node fields: @type', array('@type' => t($type['name']))), -8.5),
+      );
+    }
+  }
+
+  return $items;
+}
+
+function content_admin_edit_cck_content($id, $parents, $conf = array()) {
+  $data = explode(':', $id);
+  $type_name = $data[0];
+  $field_name = $data[1];
+  $form = array();
+  $info = _content_type_info($type_name, $field_name);
+  $field = $info['fields'][$field_name];
+  $field_info = $info['field types'][$field['type']];
+
+  $form['field_name'] = array(
+    '#type' => 'value',
+    '#value' => $field_name,
+  );
+  $form['type_name'] = array(
+    '#type' => 'value',
+    '#value' => $type_name,
+  );
+  $form['title_formatter'] = array(
+    '#type' => 'select',
+    '#title' => t('Title formatter'),
+    '#default_value' => $conf['title_formatter'],
+    '#options' => array(
+      'normal' => t('Block title'),
+      'above' => t('Above'),
+      'inline' => t('Inline'),
+      'hidden' => t('hidden'),
+    ),
+    '#description' => t('Configure how the title is going to be displayed'),
+  );
+
+  $options = array();
+  foreach ($field_info['formatters'] as $type => $formatter) {
+    $options[$type] = $formatter['label'];
+  }
+
+  $form['formatter'] = array(
+    '#type' => 'select',
+    '#title' => t('Formatter'),
+    '#default_value' => $conf['formatter'],
+    '#options' => $options,
+    '#description' => t('Select how the field is going to be displayed'),
+  );
+  return $form;
+}
+
+function content_admin_render_cck_content($conf, $panel_args, $context) {
+  if (!empty($context) && empty($context->data)) {
+    return;
+  }
+  
+  $node = isset($context->data) ? drupal_clone($context->data) : NULL;
+  $info = _content_type_info($id);
+  $field = $info['fields'][$conf['field_name']];
+  $field_info = $info['field types'][$field['type']];
+  $field_types = _content_field_types();
+  $field['display_settings']['label']['format'] = $conf['title_formatter'] == 'normal' ? 'hidden' : $conf['title_formatter'];
+  $field['display_settings']['full']['format'] = $conf['formatter'];
+
+  $block->module = 'content';
+  $block->delta = $conf['field_name'];
+
+  if ($conf['title_formatter'] == 'normal') {
+    $block->title = $field['widget']['label'];
+  }
+  $node_field = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();
+
+  if (content_handle('field', 'view', $field) == CONTENT_CALLBACK_CUSTOM) {
+    $module = $field_types[$field['type']]['module'];
+    $function = $module .'_field';
+    if (function_exists($function)) {
+      $value = $function('view', $node, $field, $node_field, 0, 0);
+    }
+  }
+  else {
+    foreach ($node_field as $delta => $item) {
+      $node_field[$delta]['view'] = content_format($field, $item, $conf['formatter'], $node);
+    }
+    $value = theme('field', $node, $field, $node_field, 0, 0);
+  }
+  $block->content = $value;
+
+  return $block;
+}
+
 /**
  * 'Render' callback for the 'CCK group' content type.
  */
@@ -58,6 +184,16 @@
   return $block;
 }
 
+
+/**
+ * 'Title' callback for the 'CCK field' content type.
+ */
+function content_admin_title_content($conf, $context) {
+  $field = content_fields($conf['field_name']);
+  $field_types = _content_field_types();
+  return t('"@s" node field @name', array('@s' => $context->identifier, '@name' => $field_types[$field['type']]['label'] .': '. $field['widget']['label'] .' ('. $field['field_name'])) .')';
+}
+
 /**
  * Allows users to theme the group
  */
@@ -71,17 +207,16 @@
 function content_admin_content_types_node_cck_group() {
   return array(
     'description' => array(
-      'title' => t('CCK Group'),
+      'title' => t('Fieldgroup'),
       'icon' => 'icon_node.png',
       'path' => panels_get_path('content_types/node'),
-      'description' => t('Group contents.'),
+      'description' => t('All fields from a fieldgroup on this node.'),
       'required context' => new panels_required_context(t('Node'), 'node'),
       'category' => array(t('Node context'), -9),
     ),
   );
 }
 
-
 /**
  * 'Edit' callback for the 'CCK group' content type.
  */
@@ -233,3 +368,4 @@
 
   return $form;
 }
+

