You are here

function certificate_mapping_form in Certificate 8.3

Same name and namespace in other branches
  1. 6.2 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 118
Administrative pages for Certificate module.

Code

function certificate_mapping_form(&$form, &$form_state) {
  if (!empty($form_state['node']->certificate['node_settings'])) {
    $stored = $form_state['node']->certificate['node_settings'];
  }
  else {
    $stored = array();
    $sql = "SELECT * FROM {certificate_node} cn WHERE nid = 0";
    $result = db_query($sql);
    while ($row = $result
      ->fetch()) {
      $stored[$row->mapper][$row->type] = $row->template;
    }
  }

  // Custom (module-provided) mappings.
  $mappings = module_invoke_all('certificate_map_options');
  $options = array(
    '-1' => t('- prevent certificate -'),
    '' => t('- no action -'),
  );
  foreach (certificate_certificate_load_all() as $cert) {
    $options[$cert->name] = entity_label('certificate', $cert);
  }
  asort($options);
  foreach ($mappings as $map_type => $map) {
    $form['certificate']['map'][$map_type] = array(
      '#title' => check_plain($map['title']),
      '#type' => 'fieldset',
      '#group' => TRUE,
      '#description' => filter_xss_admin($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' => filter_xss($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>',
      );
    }
  }
}