You are here

function _webform_render_grid in Webform 7.4

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

Implements _webform_render_component().

File

components/grid.inc, line 201
Webform module grid component.

Code

function _webform_render_grid($component, $value = NULL, $filter = TRUE, $submission = NULL) {
  $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
  $questions = _webform_select_options_from_text($component['extra']['questions'], TRUE);
  $options = _webform_select_options_from_text($component['extra']['options'], TRUE);
  if ($filter) {
    $questions = _webform_select_replace_tokens($questions, $node);
    $options = _webform_select_replace_tokens($options, $node);
  }
  $element = array(
    '#type' => 'webform_grid',
    '#title' => $filter ? webform_filter_xss($component['name']) : $component['name'],
    '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
    '#required' => $component['required'],
    '#weight' => $component['weight'],
    '#description' => $filter ? webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
    '#grid_questions' => $questions,
    '#grid_options' => $options,
    '#default_value' => isset($value) || !strlen($component['value']) ? $value : array_fill_keys(array_keys($questions), $component['value']),
    '#grid_default' => $component['value'],
    '#optrand' => $component['extra']['optrand'],
    '#qrand' => $component['extra']['qrand'],
    '#sticky' => $component['extra']['sticky'],
    '#theme' => 'webform_grid',
    '#theme_wrappers' => array(
      'webform_element',
    ),
    '#process' => array(
      'webform_expand_grid',
    ),
    '#element_validate' => array(
      'webform_validate_grid',
    ),
    '#translatable' => array(
      'title',
      'description',
      'grid_options',
      'grid_questions',
    ),
  );

  // Enforce uniqueness.
  if ($component['extra']['unique']) {
    $element['#element_validate'][] = '_webform_edit_grid_unique_validate';
  }
  return $element;
}