You are here

function theme_webform_civicrm_options in Webform CiviCRM Integration 7.2

Same name and namespace in other branches
  1. 6.2 webform_civicrm_d6_functions.inc \theme_webform_civicrm_options()
  2. 7.3 webform_civicrm_admin.inc \theme_webform_civicrm_options()

Theme function to format civicrm options form as a table

1 theme call to theme_webform_civicrm_options()
_webform_civicrm_webform_component_form_alter in ./webform_civicrm_admin.inc
Alter back-end webform component edit forms. Called by hook_form_alter() whenever editing a webform component.

File

./webform_civicrm_d7_functions.inc, line 91
Keep all functions specific to a version of Drupal here, to allow the rest of the code to be version-independent.

Code

function theme_webform_civicrm_options($variables) {
  $element = $variables['element'];
  if ($element['civicrm_defaults']['#type'] == 'checkboxes') {
    $default_box = '<input class="select-all-civi-defaults" type="checkbox" ' . (empty($element['civicrm_defaults']['#default_value']) ? '' : 'checked="checked"') . 'title="' . t('Select All') . '"> ';
  }
  else {
    $default_box = drupal_render($element['civicrm_defaults']['']);
  }
  $select_box = '<input class="select-all-civi-options" type="checkbox" checked="checked" title="' . t('Select All') . '"> ';
  $table = array(
    'rows' => array(),
    'attributes' => array(
      'id' => 'civicrm-options-table',
    ),
    'sticky' => FALSE,
  );
  if (empty($element['civicrm_options'])) {
    $table['header'] = array(
      t('Item'),
      $default_box . t('Selected'),
    );
  }
  else {
    $table['header'] = array(
      t('Item'),
      t('Weight'),
      $select_box . t('Enabled'),
      t('Label'),
      $default_box . t('Default'),
    );
    drupal_add_tabledrag('civicrm-options-table', 'order', 'self', 'civicrm-option-weight');
  }
  foreach (element_children($element['civicrm_defaults']) as $k) {
    if ($k) {
      $v = str_replace('_web_civi_option_selected_', '', $k);
      $row = array(
        drupal_render($element['civicrm_option_name_' . $v]),
      );
      if (!empty($element['civicrm_options'])) {
        $element['civicrm_option_weight_' . $v]['#attributes']['class'] = webform_civicrm_fapi_class('civicrm-option-weight');
        $element['civicrm_options'][$k]['#attributes']['class'] = webform_civicrm_fapi_class('civicrm-enabled');
        $element['civicrm_option_label_' . $v]['#attributes']['class'] = webform_civicrm_fapi_class('civicrm-label');
        $row[] = drupal_render($element['civicrm_option_weight_' . $v]);
        $row[] = drupal_render($element['civicrm_options'][$k]);
        $row[] = drupal_render($element['civicrm_option_label_' . $v]);
      }
      $element['civicrm_defaults'][$k]['#attributes']['class'] = webform_civicrm_fapi_class('civicrm-default');
      $row[] = drupal_render($element['civicrm_defaults'][$k]);
      $table['rows'][] = array(
        'data' => $row,
        'class' => webform_civicrm_fapi_class('draggable'),
      );
    }
  }
  drupal_render_children($element);
  return theme('table', $table);
}