You are here

function certificate_field_grouping_form in Certificate 6.2

Same name and namespace in other branches
  1. 8.3 certificate.admin.inc \certificate_field_grouping_form()
  2. 6 certificate.admin.inc \certificate_field_grouping_form()
  3. 7.3 certificate.admin.inc \certificate_field_grouping_form()
  4. 7.2 certificate.admin.inc \certificate_field_grouping_form()
  5. 3.x certificate.admin.inc \certificate_field_grouping_form()

Form to select which content profile field values are part of which group.

1 string reference to 'certificate_field_grouping_form'
certificate_menu in ./certificate.module
Implementation of hook_menu().

File

./certificate.admin.inc, line 267
Administrative pages for Certificate module.

Code

function certificate_field_grouping_form() {
  $form = array();

  // Map against a CCK content_profile field.
  if (module_exists('content_profile')) {
    $groupsinfo = variable_get('certificate_field_groups', array());
    $fieldgroups = variable_get('certificate_field_grouping', array());
    $form['certificate_add_new_group'] = array(
      '#prefix' => '<div>',
      '#suffix' => '</div>',
      '#type' => 'markup',
      '#value' => l('Add a new group?', 'admin/build/certificates/mapping/groups/add'),
    );
    $types = content_types();
    foreach ($types as $key => $type) {
      if (variable_get('content_profile_use_' . $key, 0)) {
        $profile_types[] = $key;
      }
    }
    $info = _content_type_info();
    $form['map']['#tree'] = TRUE;

    // Create multiselect box for each field key.
    foreach ($groupsinfo as $key => $title) {
      $form['map'][$key] = array(
        '#type' => 'fieldset',
        '#title' => check_plain($title),
        '#tree' => TRUE,
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      foreach ($info['content types'] as $ckey => $type) {
        if (in_array($ckey, $profile_types)) {
          foreach ($type['fields'] as $field_key => $field) {
            $options = optionwidgets_options($field, FALSE);
            if (!empty($options)) {
              $form['map'][$key][$field_key] = array(
                '#title' => check_plain($field['widget']['label']),
                '#type' => 'select',
                '#multiple' => TRUE,
                '#options' => $options,
                // This is a trick to set the default value to ' ', which doesn't
                // match anything. This was accidentally causing 'None' to
                // actually be selected as a mapping.
                '#default_value' => isset($fieldgroups[$key][$field_key]) ? $fieldgroups[$key][$field_key] : array(),
              );
            }
          }
        }
      }
    }
  }
  else {
    $form['disabled']['#value'] = '<p>' . t('Please enable content_profile to work with profile field grouping.') . '</p>';
  }
  $form['submit'] = array(
    '#value' => 'Submit',
    '#type' => 'submit',
  );
  return $form;
}