You are here

function _webform_render_grid in Webform 5

Same name and namespace in other branches
  1. 5.2 components/grid.inc \_webform_render_grid()
  2. 6.3 components/grid.inc \_webform_render_grid()
  3. 6.2 components/grid.inc \_webform_render_grid()
  4. 7.4 components/grid.inc \_webform_render_grid()
  5. 7.3 components/grid.inc \_webform_render_grid()
1 call to _webform_render_grid()
_webform_submission_display_grid in components/grid.inc
Display the result of a grid submission. The output of this function will be displayed under the "results" tab then "submissions"

File

components/grid.inc, line 71

Code

function _webform_render_grid($component, $random = true) {
  $form_item = array(
    '#title' => $component['name'],
    '#required' => $component['mandatory'],
    '#weight' => $component['weight'],
    '#theme' => 'webform_grid',
    '#description' => _webform_filtervalues($component['extra']['description']),
  );
  $questions = explode("\n", _webform_filtervalues($component['extra']['questions'], FALSE));
  $rows = explode("\n", _webform_filtervalues($component['extra']['options'], FALSE));
  if ($component['extra']['optrand'] && $random) {
    shuffle($rows);
  }
  foreach ($rows as $row) {
    if ($row != '') {
      $row = trim($row);
      if (preg_match('/^([^"|]+)\\|(.*)$/', $row, $matches)) {
        $options[$matches[1]] = $matches[2];
      }
      else {
        $options[_webform_safe_name($row)] = $row;
      }
    }
  }
  $cid = 0;
  if ($component['extra']['qrand'] && $random) {
    shuffle($questions);
  }
  foreach ($questions as $question) {
    if ($question != '') {
      $form_item[_webform_safe_name($question)] = array(
        '#title' => $question,
        '#required' => $component['mandatory'],
        '#prefix' => '<div class="webform-component-' . $component['type'] . '" id="webform-component-' . $component['form_key'] . '">',
        '#suffix' => '</div>',
        '#options' => $options,
        '#type' => 'radios',
      );
    }
  }
  return $form_item;
}