You are here

function webform_view in Webform 5

Same name and namespace in other branches
  1. 5.2 webform.module \webform_view()
  2. 6.2 webform.module \webform_view()

Implementation of hook_view().

File

./webform.module, line 1149

Code

function webform_view(&$node, $teaser = 0, $page = 0) {
  global $user;

  // If a teaser, do not display the form.
  if ($teaser) {
    $node->content['teaser'] = array(
      '#value' => check_markup($node->teaser, $node->format, FALSE),
    );
    return $node;
  }
  include_once drupal_get_path('module', 'webform') . "/webform.inc";
  $sid_to_display = isset($_GET['sid']) ? $_GET['sid'] : NULL;
  $submission = array();
  $enabled = FALSE;
  $preview = FALSE;
  if ($_POST['op'] == t('Preview')) {
    webform_prepare($node);
  }
  if (isset($sid_to_display) && is_numeric($sid_to_display)) {
    $submission = _webform_fetch_submission($sid_to_display, $node->nid);
    $enabled = isset($_GET['op']) && $_GET['op'] == 'edit' && (user_access('edit own webform submissions') && $submission['uid'] == $user->uid || user_access('edit webform submissions'));
    if (!$enabled && (!user_access('access webform results') && !(user_access('access own webform submissions') && $submission['uid'] == $user->uid))) {
      $submission = array();
    }
    else {
      drupal_set_title(t('Submission #@sid', array(
        '@sid' => $sid_to_display,
      )));
      $node->body = "";
    }
  }
  $output = drupal_get_form('webform_client_form_' . $node->nid, $node, $submission, $enabled);

  // Remove the surrounding <form> tag if this is a preview.
  if ($preview) {
    $output = preg_replace('/<\\/?form[^>]*>/', '', $output);
  }
  $node->content['body'] = array(
    '#value' => check_markup($node->body, $node->format, FALSE),
  );
  $node->content['webform'] = array(
    '#value' => $output,
    '#weight' => 1,
  );
  return $node;
}