You are here

function _webform_render_component in Webform 7.4

Same name and namespace in other branches
  1. 6.3 webform.api.php \_webform_render_component()
  2. 7.3 webform.api.php \_webform_render_component()

Render a Webform component to be part of a form.

Parameters

$component: A Webform component array.

$value: If editing an existing submission or resuming a draft, this will contain an array of values to be shown instead of the default in the component configuration. This value will always be an array, keyed numerically for each value saved in this field.

$filter: Whether or not to filter the contents of descriptions and values when rendering the component. Values need to be unfiltered to be editable by Form Builder.

$submission: The submission from which this component is being rendered. Usually not needed. Used by _webform_render_date() to validate using the submission's completion date.

Return value

array $form_item

See also

_webform_client_form_add_component()

Related topics

File

./webform.api.php, line 965
Sample hooks demonstrating usage in Webform.

Code

function _webform_render_component($component, $value = NULL, $filter = TRUE, $submission = NULL) {
  $form_item = array(
    '#type' => 'textfield',
    '#title' => $filter ? webform_filter_xss($component['name']) : $component['name'],
    '#required' => $component['required'],
    '#weight' => $component['weight'],
    '#description' => $filter ? webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'],
    '#default_value' => $filter ? webform_replace_tokens($component['value']) : $component['value'],
    '#theme_wrappers' => array(
      'webform_element',
    ),
  );
  if (isset($value)) {
    $form_item['#default_value'] = $value[0];
  }
  return $form_item;
}