From: gordonh <gordonh>
Date: Wed, 19 Mar 2008 00:39:21 +0000 (+0000)
Subject: Add in changes to CCK to allow cck fields to be added to panels
X-Git-Tag: CMS_S3_V0~37
X-Git-Url: http://localhost/gitweb/?p=lpcvs%2F.git;a=commitdiff_plain;h=2ae966dd9920bcc4946db4916d530db80836b148

Add in changes to CCK to allow cck fields to be added to panels
---

diff --git a/sites/all/modules/cck/content.module b/sites/all/modules/cck/content.module
index dfab6ca..6935ba7 100644
--- a/sites/all/modules/cck/content.module
+++ b/sites/all/modules/cck/content.module
@@ -43,6 +43,10 @@ function content_init() {
     if (module_exists('pathauto')) {
       include_once('./'. drupal_get_path('module', 'content') .'/content_pathauto.inc');
     }
+    // Load Panels information
+    if (module_exists('panels')) {
+      include_once('./'. drupal_get_path('module', 'content') .'/content_panels.inc');
+    }
   }
 }
 
diff --git a/sites/all/modules/cck/content_panels.inc b/sites/all/modules/cck/content_panels.inc
new file mode 100644
index 0000000..d286cbd
--- /dev/null
+++ b/sites/all/modules/cck/content_panels.inc
@@ -0,0 +1,116 @@
+<?php
+// $Id$
+/**
+ * Create Interface to allow cck fields to be added to a page
+ */
+
+/**
+ * Implementation of hook_panels_content_types()
+ */
+function content_panels_content_types() {
+  $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',
+  );
+  return $items;
+}
+
+function content_admin_content_types_cck_content() {
+  $fields = content_fields();
+  $items = array();
+
+  foreach ($fields as $field_name => $field) {
+    $items[$field_name] = array(
+      'title' => $field['widget']['label'],
+      'icon' => 'icon_node.png',
+      'path' => panels_get_path('content_types/node'),
+      'required context' => new panels_required_context(t('Node'), 'node'),
+      'category' => array(t('Content fields'), -9),
+    );
+  }
+
+  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;
+}
+
