You are here

function _webform_render_hidden in Webform 7.4

Same name and namespace in other branches
  1. 5.2 components/hidden.inc \_webform_render_hidden()
  2. 5 components/hidden.inc \_webform_render_hidden()
  3. 6.3 components/hidden.inc \_webform_render_hidden()
  4. 6.2 components/hidden.inc \_webform_render_hidden()
  5. 7.3 components/hidden.inc \_webform_render_hidden()

Implements _webform_render_component().

File

components/hidden.inc, line 71
Webform module hidden component.

Code

function _webform_render_hidden($component, $value = NULL, $filter = TRUE, $submission = NULL) {
  $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
  $default_value = $filter ? webform_replace_tokens($component['value'], $node) : $component['value'];
  if (isset($value[0])) {
    $default_value = $value[0];
  }
  $element = array(
    '#title' => $filter ? NULL : $component['name'],
    '#weight' => $component['weight'],
    '#translatable' => array(
      'title',
    ),
  );
  if ($component['extra']['hidden_type'] == 'value') {
    $element['#type'] = 'value';
    $element['#value'] = $default_value;
  }
  else {
    $element['#type'] = 'hidden';
    $element['#default_value'] = $default_value;

    // Same-page conditionals depend on the wrapper around elements for getting
    // values. Wrap, but hide, the wrapper around hidden elements.
    $element['#theme_wrappers'] = array(
      'webform_element',
    );
    $element['#wrapper_attributes']['class'] = array();
    $element['#wrapper_attributes']['style'] = array(
      'display: none',
    );
  }
  return $element;
}