You are here

function advpoll_generate_block_view in Advanced Poll 7.2

Same name and namespace in other branches
  1. 7.3 advpoll.module \advpoll_generate_block_view()
  2. 7 advpoll.module \advpoll_generate_block_view()
1 call to advpoll_generate_block_view()
advpoll_block_view in ./advpoll.module
Implements hook_block_view().

File

./advpoll.module, line 920

Code

function advpoll_generate_block_view($block, $delta) {

  // only run this process when there is an advanced poll
  // block to process
  $pattern = '/(?i)(advpoll)/';
  if (@preg_match($pattern, $delta)) {
    $parts = explode('_', $delta);
    $nid = $parts[count($parts) - 1];
    $isBlock = FALSE;
    $node = node_load($nid);
    isset($node->advpoll_options[$node->language]) ? $options = $node->advpoll_options[$node->language] : ($options = $node->advpoll_options['und']);

    // need to check to see if the nid is meant to display as a block or not.
    // It's possible the value gets switched off but the block id is still
    // assigned to a region and will display anyway.
    foreach ($options as $option) {
      if ($option['value'] == 'block') {
        $isBlock = TRUE;
      }
    }
    if ($isBlock) {
      $rendered_node = node_view($node);
      $block['subject'] = t('Poll');
      $block['content'] = array(
        '#markup' => drupal_render($rendered_node),
      );
    }
  }
  return $block;
}