Index: cck_blocks.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck_blocks/cck_blocks.module,v
retrieving revision 1.3
diff -u -F^function -r1.3 cck_blocks.module
--- cck_blocks.module	13 Mar 2008 16:13:30 -0000	1.3
+++ cck_blocks.module	16 Jul 2009 23:31:08 -0000
@@ -1,68 +1,74 @@
 <?php
 //$Id: cck_blocks.module,v 1.3 2008/03/13 16:13:30 fokke Exp $
 
+/**
+ * Implementation of hook_content_build_modes().
+ */
+function cck_blocks_content_build_modes() {
+  return array(
+    'cck_blocks' => array(
+      'title' => t('CCK Blocks'),
+      'build modes' => array(
+        'cck_blocks' => array(
+          'title' => t('CCK Blocks'),
+          'views style' => FALSE,
+        ),
+      ),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_block().
+ */
 function cck_blocks_block($op = 'list', $delta = 0, $edit = array()) {
+  static $built_nodes = NULL;
+  
 	$fields = module_invoke('content', 'fields');
 
 	switch ($op) {
-	
 		case 'list':
 			$blocks = array();
-			
 			if (count($fields)) {
-				
 				foreach($fields as $field_name => $field_info) {
 					$blocks[$field_name] = array('info' => 'CCK: '.($field_info['widget']['label'] ? $field_info['widget']['label'] : $field_name));
 				}
 			}
-			
 			return $blocks;
 
-		case 'configure':
-			$form = array();
-			$options = array();
-			$info = content_fields($delta);
-			$type_info = _content_type_info();
-			foreach ($type_info['field types'][$info['type']]['formatters'] as $name => $formatter) {
-				$options[$name] = $formatter['label'];
-			}
-			$options['hidden'] = t('<Hidden>');
-			$settings = variable_get('cck_blocks_' . $delta, array('formatter' => 'default'));
-			$form['formatter'] = array(
-				'#title' => t('Display'),
-				'#type' => 'select',
-				'#description' => t('Configure how this field should be displayed when it is viewed in a block.'), 
-				'#options' => $options,
-				'#default_value' => $settings['formatter'],
-			);
-			return $form;
-			
-    case 'save':
-      $settings = variable_get('cck_blocks_' . $delta, array('formatter' => 'default'));
-      $settings['formatter'] = $edit['formatter'];
-      variable_set('cck_blocks_' . $delta, $settings);
-      return;
-	  
     case 'view':
-	default:
-		$block = array();
+      $block = array();
 	
-		if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2) && $fields[$delta]) {
-			$node = node_load(arg(1));
+      if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2) && $fields[$delta]) {
+        $nid = arg(1);
+        if (!isset($built_nodes[$nid])) {
+          // Build the node in the cck_blocks mode. This is based on node_build_content().
+          $node = node_load($nid);
+          $node->build_mode = 'cck_blocks';
+      
+          // Remove the delimiter (if any) that separates the teaser from the body.
+          $node->body = isset($node->body) ? str_replace('<!--break-->', '', $node->body) : '';
 
-			if ($items = $node->$delta) {
-				$block['subject'] = $fields[$delta]['widget']['label'] ? $fields[$delta]['widget']['label'] : $delta;
-				$block['content'] = '';
-				
-				$settings = variable_get('cck_blocks_' . $delta, array('formatter' => 'default'));				
-				foreach ($items as $item) {
-					$block['content'] .= module_invoke('content', 'format', $fields[$delta], $item, $settings['formatter'], $node);
-				}
-			}
-		}
+          // The 'view' hook can be implemented to overwrite the default function
+          // to display nodes.
+          if (node_hook($node, 'view')) {
+            $node = node_invoke($node, 'view', $teaser, $page);
+          }
+          else {
+            $node = node_prepare($node, $teaser);
+          }
 
-		return $block;
-	}
+          // Allow modules to make their own additions to the node.
+          node_invoke_nodeapi($node, 'view', $teaser, $page);
+          $built_nodes[$nid] = $node;
+        }
+        
+        if (isset($built_nodes[$nid]->content[$delta])) {
+          $block['subject'] = $fields[$delta]['widget']['label'] ? $fields[$delta]['widget']['label'] : $delta;
+          $block['content'] = drupal_render($built_nodes[$nid]->content[$delta]);
+        }
+      }
+  }
+  
+  return $block;
 }
-
-?>
\ No newline at end of file
