You are here

function certificate_type_mapping_form in Certificate 6.2

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

Returns the form for the per-node certificate settings.

This is shared by the settings page and the node edit page.

Parameters

$node: The fully loaded node object if we've got it.

Return value

The form array for the per-node certificate settings.

File

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

Code

function certificate_type_mapping_form($form_state, $node = NULL) {

  // Get existing node-specific template settings.
  $node_template_settings = $node->certificate['node_settings'];

  // Get existing templates.
  $templates = certificate_certificate_load_all();
  $template_options[0] = 'Global';
  foreach ($templates as $key => $template) {
    $template_options[$key] = $template['title'];
  }
  if (variable_get('certificate_field_grouping', 0)) {

    // Group stuff
    $fieldgroups = variable_get('certificate_field_groups', array());

    // Generate form elements based on selected field's allowed values.
    if (count($fieldgroups)) {
      foreach ($fieldgroups as $key => $fieldgroup) {

        // We don't care about $fieldgroup - just the key.
        // Get node-based setting, if not set, use global.
        if ($node) {
          $template = $node_template_settings[$key];
          $template = $template ? $template : 0;
        }
        else {
          $template = variable_get("certificate_type_{$key}_template", 0);
        }
        $form[$key] = array(
          '#type' => 'select',
          '#title' => check_plain($key),
          '#options' => $template_options,
          '#default_value' => $template,
        );
      }
    }
    else {
      $form['nogroups'] = array(
        '#prefix' => '<p>',
        '#suffix' => '</p>',
        '#value' => t("Please go to !groups to configure certificate field mapping groups.", array(
          '!groups' => l('groups', 'admin/build/certificates/mapping/groups'),
        )),
      );
    }
  }
  else {

    // Get field's options from types selection.
    $field_options_array = certificate_get_selected_type_options();
    if (arg(0) == 'node' && !count($field_options_array)) {
      $form['#type'] = 'markup';
      $form['#value'] = "<div>" . t("Please !link before using certificates.", array(
        '!link' => l('set up field mappings', 'admin/build/certificates/mapping'),
      )) . "</div>";
    }

    // Generate form elements based on selected field's allowed values.
    if ($field_options_array) {
      foreach ($field_options_array as $key => $option_name) {

        // Get node-based setting, if not set, use global.
        if ($node) {
          $template = $node_template_settings[$key];
          $template = $template ? $template : 0;
        }
        else {
          $template = variable_get("certificate_type_{$key}_template", 0);
        }
        $form[$key] = array(
          '#type' => 'select',
          '#title' => check_plain($option_name),
          '#options' => $template_options,
          '#default_value' => $template,
        );
      }
    }
  }
  return $form;
}