When using this component, we don't get display value to table view and CSV exports under results tab.

CommentFileSizeAuthor
#4 webform_boolean-1912524-4.patch1.76 KBimiksu

Comments

steveEngine’s picture

Category: support » feature
Status: Active » Needs review

Here's a patch to provide the functionality.

/**
 * Implements _webform_table_component().
 */
function _webform_table_boolean($component, $value) {
  return empty($value[0]) ? '' : ($value[0] ? $component['extra']['off_value'] : $component['extra']['on_value']);
}

/**
 * Implements _webform_csv_headers_component().
 */
function _webform_csv_headers_boolean($component, $export_options) {
  $header = array();
  $header[0] = '';
  $header[1] = '';
  $header[2] = $component['name'];
  return $header;
}

/**
 * Implements _webform_csv_data_component().
 */
function _webform_csv_data_boolean($component, $export_options, $value) {
  $return;
  if(!isset($value[0])) {
    $return = '';
  } else {
    // seems backwards...
    $return = ($value[0] ? $component['extra']['on_value'] : $component['extra']['off_value']);
  }
  return $return;
}
steveEngine’s picture

If you don't know where that code goes, paste that into the bottom of $DRUPAL_ROOT$/sites/all/modules/webform_boolean/components/boolean.inc

(without the php tags)

dtdpro’s picture

Table was reporting incorrect value, try this instead

<?php
/**
 * Implements _webform_table_component().
 */
function _webform_table_boolean($component, $value) { 
  $return;
  if(!isset($value[0])) {
    $return = '';
  } else {
    // seems backwards...
    $return = ($value[0] ? $component['extra']['on_value'] : $component['extra']['off_value']);
  }
  return $return;
}

/**
 * Implements _webform_csv_headers_component().
 */
function _webform_csv_headers_boolean($component, $export_options) {
  $header = array();
  $header[0] = '';
  $header[1] = '';
  $header[2] = $component['name'];
  return $header;
}

/**
 * Implements _webform_csv_data_component().
 */
function _webform_csv_data_boolean($component, $export_options, $value) {
  $return;
  if(!isset($value[0])) {
    $return = '';
  } else {
    // seems backwards...
    $return = ($value[0] ? $component['extra']['on_value'] : $component['extra']['off_value']);
  }
  return $return;
}
?>
imiksu’s picture

Issue summary: View changes
StatusFileSize
new1.76 KB

Since CSV export and table value reporting is same, I've created a helper function for it.

I also covered a case where we don't have on/off values set (it's optional), so we need to check if that's empty and set default 1/0 when they aren't set from component configuration.

Here's patch file based on code above together with my improvements.

jaxxed’s picture

Status: Needs review » Reviewed & tested by the community

We've been using this patch for about 8 months since Miksu proposed it. Should it be mainlined?

  • anthonyleach committed 9aaed26 on 7.x-1.x authored by iMiksu
    Issue #1912524 by iMiksu: Boolean fields don't show up in webform...
anthonyleach’s picture

Status: Reviewed & tested by the community » Closed (fixed)