| 1 |
<?php
|
| 2 |
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_content_build_modes().
|
| 6 |
*/
|
| 7 |
function cck_blocks_content_build_modes() {
|
| 8 |
return array(
|
| 9 |
'cck_blocks' => array(
|
| 10 |
'title' => t('CCK Blocks'),
|
| 11 |
'build modes' => array(
|
| 12 |
'cck_blocks' => array(
|
| 13 |
'title' => t('CCK Blocks'),
|
| 14 |
'views style' => FALSE,
|
| 15 |
),
|
| 16 |
),
|
| 17 |
),
|
| 18 |
);
|
| 19 |
}
|
| 20 |
|
| 21 |
/**
|
| 22 |
* Implementation of hook_block().
|
| 23 |
*/
|
| 24 |
function cck_blocks_block($op = 'list', $delta = 0, $edit = array()) {
|
| 25 |
static $built_nodes = NULL;
|
| 26 |
|
| 27 |
$fields = module_invoke('content', 'fields');
|
| 28 |
|
| 29 |
switch ($op) {
|
| 30 |
case 'list':
|
| 31 |
$blocks = array();
|
| 32 |
if (count($fields)) {
|
| 33 |
foreach($fields as $field_name => $field_info) {
|
| 34 |
$blocks[$field_name] = array('info' => 'CCK: '.($field_info['widget']['label'] ? $field_info['widget']['label'] : $field_name));
|
| 35 |
}
|
| 36 |
}
|
| 37 |
return $blocks;
|
| 38 |
|
| 39 |
case 'view':
|
| 40 |
$block = array();
|
| 41 |
|
| 42 |
if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2) && $fields[$delta]) {
|
| 43 |
$nid = arg(1);
|
| 44 |
if (!isset($built_nodes[$nid])) {
|
| 45 |
// Build the node in the cck_blocks mode. This is based on node_build_content().
|
| 46 |
$node = node_load($nid);
|
| 47 |
$node->build_mode = 'cck_blocks';
|
| 48 |
|
| 49 |
// Remove the delimiter (if any) that separates the teaser from the body.
|
| 50 |
$node->body = isset($node->body) ? str_replace('<!--break-->', '', $node->body) : '';
|
| 51 |
|
| 52 |
// The 'view' hook can be implemented to overwrite the default function
|
| 53 |
// to display nodes.
|
| 54 |
if (node_hook($node, 'view')) {
|
| 55 |
$node = node_invoke($node, 'view', $teaser, $page);
|
| 56 |
}
|
| 57 |
else {
|
| 58 |
$node = node_prepare($node, $teaser);
|
| 59 |
}
|
| 60 |
|
| 61 |
// Allow modules to make their own additions to the node.
|
| 62 |
node_invoke_nodeapi($node, 'view', $teaser, $page);
|
| 63 |
$built_nodes[$nid] = $node;
|
| 64 |
}
|
| 65 |
|
| 66 |
if (isset($built_nodes[$nid]->content[$delta])) {
|
| 67 |
$block['subject'] = $fields[$delta]['widget']['label'] ? $fields[$delta]['widget']['label'] : $delta;
|
| 68 |
$block['content'] = drupal_render($built_nodes[$nid]->content[$delta]);
|
| 69 |
}
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
return $block;
|
| 74 |
}
|