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	23 Apr 2008 12:54:42 -0000
@@ -1,11 +1,23 @@
 <?php
 // $Id: content_panels.inc,v 1.1.2.10 2008/03/23 16:30:59 yched Exp $
+/**
+ * Create Interface to allow cck fields to be added to a page
+ */
 
 /**
- * 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',
+  );
   if (module_exists('fieldgroup')) {
     $items['node_cck_group'] = array(
       'title' => t('Node CCK Group'),
@@ -20,6 +32,105 @@
   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()) {
+  $form = array();
+  $info = _content_type_info($id);
+  $field = $info['fields'][$id];
+  $field_info = $info['field types'][$field['type']];
+
+  $form['field_name'] = array(
+    '#type' => 'value',
+    '#value' => $id,
+  );
+  $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['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 = $field['type'] .'_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.
  */
@@ -81,7 +192,6 @@
   );
 }
 
-
 /**
  * 'Edit' callback for the 'CCK group' content type.
  */
@@ -233,3 +343,4 @@
 
   return $form;
 }
+

