You are here

function _webform_render_node in Webform Node Element 7

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

Implements _webform_render_component().

File

components/node.inc, line 120
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();
  }
  $content = node_view($node, $component['extra']['view_mode']);

  // If there is a read-more link, default that to a new browser window.
  if (!empty($content['links']['node']['#links']['node-readmore'])) {
    $content['links']['node']['#links']['node-readmore']['attributes']['target'] = '_new';
  }
  $element = array(
    '#type' => 'hidden',
    '#title' => $component['extra']['title'] ? check_plain($node->title) : $component['name'],
    '#weight' => $component['weight'],
    '#default_value' => render($content),
    '#input_format' => 'html',
    '#theme_wrappers' => array(
      'webform_node_element_node',
    ),
    '#webform_component' => $component,
  );
  $element['#field_value'] = $element['#default_value'];
  return $element;
}