You are here

function webformblock_view in Webform Block 6.3

Same name and namespace in other branches
  1. 6 webformblock.module \webformblock_view()

Use the block delta to load in the corresponding node and output as a block body Block content can be themed as if it was a node-webform.tpl.php etc.

1 call to webformblock_view()
webformblock_block in ./webformblock.module
Exposes blocks to match any webforms which have been activated

File

./webformblock.module, line 160
Expose webform nodes as Drupal blocks.

Code

function webformblock_view($nid) {
  if (!webformblock_exists($nid)) {
    return;
  }
  $node = node_load($nid);

  // Check if the user can add another submission.
  if ($node->webform['submit_limit'] != -1) {

    // -1: Submissions are never throttled.
    module_load_include('inc', 'webform', 'webform_submissions');

    // Return if the limit is exceeded and page cache is not active.
    if (($limit_exceeded = _webform_submission_limit_check($node)) && ($user->uid != 0 || variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED)) {
      return;
    }
  }

  // Remember the node title to use for the block title, but don't print the title in the block content
  $block_subject = check_plain($node->title);
  $node->title = '';
  $teaser = variable_get('webformblock_use_teaser_' . $node->nid, FALSE);
  $node = node_view($node, $teaser, FALSE, FALSE);

  // Provide an anchor to jump to the embedded contact form
  $anchorname = form_clean_id(str_replace('/', '', strtolower(drupal_get_path_alias('node/' . $node->nid))));
  $content = '<a name="' . $anchorname . '"></a>' . $node;
  $block = array(
    'subject' => $block_subject,
    'content' => $content,
  );
  return $block;
}