You are here

function _webform_edit_node in Webform Node Element 7

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

Implements _webform_edit_component().

File

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

Code

function _webform_edit_node($component) {
  $form = array();

  // Load the available view modes for 'node' entities, so users can also
  // choose custom ones if they have defined any.
  // Maybe RSS and search results shouldn't be listed. Maybe. Dunno.
  $view_modes = array();
  $data = entity_get_info('node');
  foreach ($data['view modes'] as $key => $value) {
    $view_modes[$key] = $value['label'];
  }
  $form['value'] = array(
    '#type' => 'textfield',
    '#size' => 5,
    '#title' => t('Node'),
    '#default_value' => $component['value'],
    '#description' => t('Enter a valid node id, whose body will be shown as markup in the webform.') . theme('webform_token_help'),
    '#weight' => -1,
    '#element_validate' => array(
      '_webform_edit_validate_node',
    ),
  );
  $form['extra']['nid'] = array(
    '#type' => 'hidden',
    '#default_value' => $component['extra']['nid'],
  );
  $form['extra']['view_mode'] = array(
    '#type' => 'radios',
    '#title' => t('Display Mode'),
    '#default_value' => $component['extra']['view_mode'],
    '#description' => t('Choose how you want the referenced node to be displayed.'),
    '#options' => $view_modes,
  );
  $form['extra']['title'] = array(
    '#type' => 'checkbox',
    '#title' => t('Override Title'),
    '#default_value' => $component['extra']['title'],
    '#description' => t('If checked, the title of the referenced node will be used as the component label.'),
    '#options' => array(
      0,
      1,
    ),
  );
  $form['extra']['description'] = array();
  $form['display'] = array(
    '#type' => 'markup',
  );

  // Hide the display options.
  // If ctools is present, use node title autocomplete.
  if (module_exists('ctools')) {
    $form['value']['#description'] = t('Enter a valid node id, or start typing to find the node whose body will be shown as markup in the webform.') . theme('webform_token_help');
    $form['value']['#autocomplete_path'] = 'ctools/autocomplete/node';
    unset($form['value']['#size']);
  }
  return $form;
}