You are here

function certificate_mapping_form in Certificate 6.2

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

Add mapping elements to a form.

2 calls to certificate_mapping_form()
certificate_alter_node_form in ./certificate.admin.inc
Alters the node form to inject the appropriate per-node template settings.
certificate_settings_form in ./certificate.admin.inc
Form for global mappings.

File

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

Code

function certificate_mapping_form(&$form, &$form_state) {
  if (isset($form['nid']['#value'])) {
    $nid = $form['nid']['#value'];
  }
  else {
    $nid = 0;
  }
  $stored = array();
  $sql = "select * from {certificate_node} cn where nid = %d";
  $result = db_query($sql, $nid);
  while ($row = db_fetch_object($result)) {
    $stored[$row->mapper][$row->type] = $row->template;
  }

  // Custom (module-provided) mappings.
  $mappings = module_invoke_all('certificate_map_options');
  $options = array(
    '' => '- no certificate -',
  );
  foreach (certificate_certificate_load_all() as $cert) {
    $options[$cert['nid']] = $cert['title'];
  }
  foreach ($mappings as $map_type => $map) {
    $form['certificate']['map'][$map_type] = array(
      '#title' => check_plain($map['title']),
      '#type' => 'fieldset',
      '#group' => TRUE,
      '#description' => check_plain($map['description']),
      '#collapsed' => TRUE,
      '#collapsible' => TRUE,
    );
    if (count($map['options'])) {
      foreach ($map['options'] as $key => $title) {
        $form['certificate']['map'][$map_type][$key] = array(
          '#type' => 'select',
          '#title' => check_plain($title),
          '#options' => $options,
          '#default_value' => isset($stored[$map_type][$key]) ? $stored[$map_type][$key] : NULL,
        );
      }
    }
    else {
      $form['certificate']['map'][$map_type]['empty'] = array(
        '#value' => '<p>' . t('There are no mappings available for %title.', array(
          '%title' => $map['title'],
        )) . '</p>',
      );
    }
  }
}