You are here

function headerimage_block in Header image 6

Same name and namespace in other branches
  1. 5 headerimage.module \headerimage_block()

Implementation of hook_block().

File

./headerimage.module, line 117
headerimage.module Conditionally display an node in a block.

Code

function headerimage_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $headerimage_blocks = headerimage_get_blocks();
      foreach ($headerimage_blocks as $key => $name) {
        $blocks[$key]['info'] = check_plain($name);
      }
      return $blocks;
      break;
    case 'configure':
      return headerimage_block_configure($delta);
    case 'save':
      variable_set('headerimage_block_' . $delta . '_random_fallback', $edit['random_fallback']);
      break;
    case 'view':
      if (user_access('view header image')) {

        // select node from nodes assigned to this block
        $nid = headerimage_select_node($delta);
        $teaser = variable_get('headerimage_teaser', true);

        // prepare block output
        if (!empty($nid)) {
          $node = node_load($nid);
          $node = node_prepare($node, $teaser);

          //use node teaser view

          // mimic node_view
          $node = node_build_content($node, $teaser, false);
          $content = drupal_render($node->content);
          if ($teaser) {
            $node->teaser = $content;
            unset($node->body);
          }
          else {
            $node->body = $content;
            unset($node->teaser);
          }
          node_invoke_nodeapi($node, 'alter', $teaser);
          $block['content'] = theme('headerimage_block', $node, $teaser);
          return $block;
        }
      }
      break;
  }
}