function terms_of_use_form_user_register_alter in Terms of Use 6
Implementation of hook_form_form_id_alter().
File
- ./
terms_of_use.module, line 130 - Adds Terms of Use to the 'user_register' form.
Code
function terms_of_use_form_user_register_alter(&$form, $form_state) {
// Administrative users can skip this. So admin/user/user/create won't show
// the terms of use.
if (user_access('administer users')) {
return;
}
$fieldset_name = filter_xss(variable_get('terms_of_use_fieldset_name', t('Terms of Use')));
$checkbox_label = filter_xss_admin(variable_get('terms_of_use_checkbox_label', t('I agree with these terms.')));
// Adding the fieldset.
$form['terms_of_use'] = array(
'#type' => 'fieldset',
'#title' => $fieldset_name,
'#weight' => 10,
);
$show_terms = TRUE;
// Getting the nid of the the Terms of Use node.
$terms_of_use_node_id = variable_get('terms_of_use_node_id', 0);
// If the translation module is active the node might be available in other
// languages.
if (module_exists('translation')) {
$translations = translation_node_get_translations($terms_of_use_node_id);
if (!empty($translations[$GLOBALS['language']->language])) {
$terms_of_use_node_id = $translations[$GLOBALS['language']->language]->nid;
}
}
// A nid for the desired language was found.
if ($terms_of_use_node_id) {
$node = node_load($terms_of_use_node_id);
// The node could be loaded.
if ($node->nid) {
// Show terms on the registration for or just a link?s
if (strpos($checkbox_label, '@link') !== FALSE) {
$checkbox_label = str_replace('@link', l($node->title, 'node/' . $node->nid), $checkbox_label);
$show_terms = FALSE;
}
// Adding the nodes body by theme_terms_of_use() to the fieldset if desired.
if ($show_terms) {
$node = node_prepare(node_load($terms_of_use_node_id));
if ($node->body) {
drupal_add_css(drupal_get_path('module', 'terms_of_use') . '/terms_of_use.css');
$form['terms_of_use']['terms_of_use_text'] = array(
'#value' => theme('terms_of_use', $node->body, $node),
);
}
else {
watchdog('Terms of use', 'The body field of the terms of use node was empty. Please check the the nodes content.', array(), WATCHDOG_ALERT, l('Administer terms of use', 'admin/settings/terms_of_use'));
}
}
}
else {
watchdog('Terms of use', 'The terms of use node could not be loaded. Please check the settings and the node.', array(), WATCHDOG_ALERT, l('Administer terms of use', 'admin/settings/terms_of_use'));
}
}
else {
watchdog('Terms of use', 'No node is set to use as terms of use in the currecnt language [' . $GLOBALS['language']->language . '].', array(), WATCHDOG_NOTICE, l('Administer terms of use', 'admin/settings/terms_of_use'));
}
// Checkbox validate handles denoting required checkboxes for us
if (module_exists('checkbox_validate')) {
$asterisk = '';
}
else {
$asterisk = ' <span class="form-required" title="' . t('This field is required') . '">*</span>';
}
// Adding the checkbox to the fieldset.
$form['terms_of_use']['terms_of_use'] = array(
'#type' => 'checkbox',
'#title' => $checkbox_label . $asterisk,
'#required' => TRUE,
'#element_validate' => array(
'_terms_of_use_validate_checkbox',
),
);
return $form;
}