You are here

function _webform_render_node in Webform Node Element 6

Same name and namespace in other branches
  1. 7 components/node.inc \_webform_render_node()

Implements _webform_render_component().

File

components/node.inc, line 112
Webform module node component.

Code

function _webform_render_node($component, $value = NULL, $filter = TRUE) {
  $node = node_load($component['extra']['nid']);

  // Add a bit of error checking; the target node may have been deleted.
  if (empty($node->nid)) {
    drupal_set_message(t('Unable to load referenced node id !nid', array(
      '!nid' => $component['extra']['nid'],
    )), 'error');
    return array();
  }

  // All good, render the node body in the chosen format.
  $component['#field_value'] = node_view($node, $component['extra']['view_mode']);
  $element = array(
    '#type' => 'hidden',
    '#title' => $component['extra']['title'] ? check_plain($node->title) : $component['name'],
    '#weight' => $component['weight'],
    '#default_value' => $component['extra']['nid'],
    '#input_format' => 'html',
    '#prefix' => _webform_node_element_prefix($component),
    '#suffix' => _webform_node_element_suffix($component),
    '#webform_component' => $component,
  );
  if (isset($value)) {
    $element['#default_value'] = $value[0];
  }
  return $element;
}