function certificate_mapping_form in Certificate 3.x
Same name and namespace in other branches
- 8.3 certificate.admin.inc \certificate_mapping_form()
- 6.2 certificate.admin.inc \certificate_mapping_form()
- 7.3 certificate.admin.inc \certificate_mapping_form()
- 7.2 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 120 - 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['nid']] = check_plain($cert['title']);
}
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>',
);
}
}
}