You are here

function theme_webform_civicrm_options_table in Webform CiviCRM Integration 7.5

Same name and namespace in other branches
  1. 7.4 includes/wf_crm_admin_component.inc \theme_webform_civicrm_options_table()

Drupal theme callback Format civicrm options form as a table

1 theme call to theme_webform_civicrm_options_table()
wf_crm_admin_component::buildOptionsTable in includes/wf_crm_admin_component.inc
Interface similar to options_element module but with the important difference that options already exist in the civi db so this does not allow create/delete of options

File

includes/wf_crm_admin_component.inc, line 638

Code

function theme_webform_civicrm_options_table($variables) {
  $element = $variables['element'];
  $element['civicrm_defaults']['']['#attributes']['class'][] = 'select-all-civi-defaults';
  $default_box = drupal_render($element['civicrm_defaults']['']);
  $select_box = '<input class="select-all-civi-options" type="checkbox" checked="checked" title="' . t('Select All') . '"> ';
  $table = [
    'rows' => [],
    'attributes' => [
      'id' => 'civicrm-options-table',
    ],
    'sticky' => FALSE,
  ];
  if (empty($element['civicrm_options'])) {
    $table['header'] = [
      t('Item'),
      $default_box . t('Selected'),
    ];
  }
  else {
    $table['header'] = [
      t('Item'),
      t('Weight'),
      [
        'data' => $select_box . t('Enabled'),
        'class' => [
          'live-options-hide',
        ],
      ],
      [
        'data' => t('Label'),
        'class' => [
          'live-options-hide',
        ],
      ],
      $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 = [
        drupal_render($element['civicrm_option_name_' . $v]),
      ];
      if (!empty($element['civicrm_options'])) {
        $element['civicrm_option_weight_' . $v]['#attributes']['class'] = [
          'civicrm-option-weight',
        ];
        $element['civicrm_options'][$k]['#attributes']['class'] = [
          'civicrm-enabled',
        ];
        $element['civicrm_option_label_' . $v]['#attributes']['class'] = [
          'civicrm-label',
        ];
        $row[] = drupal_render($element['civicrm_option_weight_' . $v]);
        $row[] = [
          'data' => drupal_render($element['civicrm_options'][$k]),
          'class' => [
            'live-options-hide',
          ],
        ];
        $row[] = [
          'data' => drupal_render($element['civicrm_option_label_' . $v]),
          'class' => [
            'live-options-hide',
          ],
        ];
      }
      $element['civicrm_defaults'][$k]['#attributes']['class'] = [
        'civicrm-default',
      ];
      $row[] = drupal_render($element['civicrm_defaults'][$k]);
      $table['rows'][] = [
        'data' => $row,
        'class' => [
          'draggable',
        ],
      ];
    }
  }
  return drupal_render_children($element) . theme('table', $table);
}