You are here

function _webform_render_grid in Webform 6.2

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. 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 79
Webform module grid component.

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_filter_descriptions($component['extra']['description']),
  );
  $questions = _webform_grid_options($component['extra']['questions']);
  $options = _webform_grid_options($component['extra']['options']);
  if ($component['extra']['optrand'] && $random) {

    // This maneuver shuffles the array keys, then uses them as
    // the basis for ordering the options.
    $aux = array();
    $keys = array_keys($options);
    shuffle($keys);
    foreach ($keys as $key) {
      $aux[$key] = $options[$key];
      unset($options[$key]);
    }
    $options = $aux;
  }
  if ($component['extra']['qrand'] && $random) {
    $aux = array();
    $keys = array_keys($questions);
    shuffle($keys);
    foreach ($keys as $key) {
      $aux[$key] = $questions[$key];
      unset($questions[$key]);
    }
    $questions = $aux;
  }
  foreach ($questions as $question) {
    if ($question != '') {

      // Remove quotes from keys to prevent HTML breakage.
      $form_item[str_replace(array(
        '"',
        "'",
      ), '', $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;
}