function advpoll_generate_block_view in Advanced Poll 7.3
Same name and namespace in other branches
- 7 advpoll.module \advpoll_generate_block_view()
- 7.2 advpoll.module \advpoll_generate_block_view()
Fetches nodes associated with a poll block.
Parameters
$block: Reference to block object
$delta: The delta of the requested block.
Return value
Returns a block array.
1 call to advpoll_generate_block_view()
- advpoll_block_view in ./
advpoll.module - Implements hook_block_view().
File
- ./
advpoll.module, line 1026
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)) {
// Check to see if the page that is loading this block is a node page.
$loaded_node = menu_get_object();
$parts = explode('_', $delta);
$nid = $parts[count($parts) - 1];
$is_block = FALSE;
if ($nid) {
$node = node_load($nid);
/* Had to test against type - value was returning a boolean but
* simply doing if ($node) still indicated the node existed.
*/
if (gettype($node) == 'object') {
isset($node->advpoll_options[$node->language]) ? $options = $node->advpoll_options[$node->language] : ($options = $node->advpoll_options[LANGUAGE_NONE]);
/* 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') {
$is_block = TRUE;
}
}
if ($is_block) {
// Prevent block from showing on its node's page.
if ($loaded_node) {
if ($loaded_node->nid == $node->nid) {
return $block;
}
}
$block['subject'] = t('Poll');
$block['content'] = node_view($node);
}
}
}
}
return $block;
}