You are here

function _webform_display_grid in Webform 7.4

Same name and namespace in other branches
  1. 6.3 components/grid.inc \_webform_display_grid()
  2. 7.3 components/grid.inc \_webform_display_grid()

Implements _webform_display_component().

File

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

Code

function _webform_display_grid($component, $value, $format = 'html', $submission = array()) {
  $node = node_load($component['nid']);
  $questions = _webform_select_options_from_text($component['extra']['questions'], TRUE);
  $questions = _webform_select_replace_tokens($questions, $node);
  $options = _webform_select_options_from_text($component['extra']['options'], TRUE);
  $options = _webform_select_replace_tokens($options, $node);
  $element = array(
    '#title' => $component['name'],
    '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
    '#weight' => $component['weight'],
    '#format' => $format,
    '#grid_questions' => $questions,
    '#grid_options' => $options,
    '#default_value' => $value,
    '#sticky' => $component['extra']['sticky'],
    '#theme' => 'webform_display_grid',
    '#theme_wrappers' => $format == 'html' ? array(
      'webform_element',
    ) : array(
      'webform_element_text',
    ),
    '#sorted' => TRUE,
    '#translatable' => array(
      '#title',
      '#grid_questions',
      '#grid_options',
    ),
  );
  foreach ($questions as $key => $question) {
    if ($question !== '') {
      $element[$key] = array(
        '#title' => $question,
        '#value' => isset($value[$key]) ? $value[$key] : NULL,
        '#translatable' => array(
          '#title',
          '#value',
        ),
      );
    }
  }
  return $element;
}