function webform_block_view in Webform 6.3
Same name and namespace in other branches
- 7.4 webform.module \webform_block_view()
- 7.3 webform.module \webform_block_view()
Implements hook_block_view().
1 call to webform_block_view()
- webform_block in ./
webform.module - Implements hook_block().
File
- ./
webform.module, line 1606
Code
function webform_block_view($delta = '') {
global $user;
// Load the block-specific configuration settings.
$webform_blocks = variable_get('webform_blocks', array());
$settings = isset($webform_blocks[$delta]) ? $webform_blocks[$delta] : array();
$settings += array(
'display' => 'form',
'pages_block' => 0,
);
// Get the node ID from delta.
$nid = drupal_substr($delta, strrpos($delta, '-') + 1);
// Load node in current language.
if (module_exists('translation')) {
global $language;
if (($translations = translation_node_get_translations($nid)) && isset($translations[$language->language])) {
$nid = $translations[$language->language]->nid;
}
}
// The webform node to display in the block.
$node = node_load($nid);
// Return if user has no access to the webform node.
if (!node_access('view', $node)) {
return;
}
// This is a webform node block.
$node->webform_block = TRUE;
// If not displaying pages in the block, set the #action property on the form.
if ($settings['pages_block']) {
$node->webform['action'] = FALSE;
}
else {
$query = array_diff_key($_GET, array(
'q' => '',
));
$node->webform['action'] = url('node/' . $node->nid, array(
'query' => $query,
));
}
// Generate the content of the block based on display settings.
if ($settings['display'] == 'form') {
webform_node_view($node, FALSE, TRUE, FALSE);
$content = $node->content['webform']['#value'];
}
else {
$teaser = $settings['display'] == 'teaser' ? TRUE : FALSE;
$content = node_view($node, $teaser, TRUE, FALSE);
}
// Create the block, using the node title for the block title.
$block = array(
'subject' => check_plain($node->title),
'content' => $content,
);
return $block;
}