function signup_alter_node_form in Signup 5
Same name and namespace in other branches
- 5.2 signup.module \signup_alter_node_form()
- 6.2 includes/node_form.inc \signup_alter_node_form()
- 6 includes/node_form.inc \signup_alter_node_form()
- 7 includes/node_form.inc \signup_alter_node_form()
Alters the node form to inject the appropriate per-node signup settings.
1 call to signup_alter_node_form()
- signup_form_alter in ./
signup.module - Implementation of hook_form_alter().
File
- ./
signup.module, line 311
Code
function signup_alter_node_form($form_id, &$form) {
global $user;
// Load the node if it already exists.
if (!empty($form['nid']['#value'])) {
$node = node_load($form['nid']['#value']);
}
else {
$node = NULL;
}
$signup_enabled = variable_get('signup_form_' . $form['type']['#value'], 0);
// If the current user has global signup administration permissions,
// or if this node-type is signup-enabled and the user has permission
// to administer signups for their own content, add a fieldset for
// signup-related settings.
if (user_access('administer all signups') || !empty($node) && $signup_enabled && $node->uid == $user->uid && user_access('administer signups for own content')) {
$form['signup'] = array(
'#type' => 'fieldset',
'#title' => t('Signup settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 30,
);
// Figure out what the options should be. If there are already
// people signed-up for this node, we need a 3rd choice: disable
// signups and remove all signup data.
$has_signups = !empty($node) && db_result(db_query("SELECT COUNT(*) from {signup_log} WHERE nid = %d", $node->nid));
$radio_options[1] = t('Enabled');
if ($has_signups) {
$radio_options[0] = t('Disabled, but save existing signup information');
$radio_options[2] = t('Disabled, and remove all signup information') . ' <strong>(' . t('This can not be undone, use with extreme caution!') . ')</strong>';
}
else {
$radio_options[0] = t('Disabled');
}
// Figure out what the default selection for signups should be.
if (isset($node->signup)) {
$default_option = $node->signup;
}
else {
$default_option = $signup_enabled;
}
if ($default_option == 1) {
$hint = t('If enabled, you can control whether users may sign up by visiting the !signups tab and toggling if signups are %open or %closed for this @node_type.', array(
'!signups' => !empty($node) ? l(t('Signups'), 'node/' . $node->nid . '/signups') : theme('placeholder', t('Signups')),
'%open' => t('open'),
'%closed' => t('closed'),
'@node_type' => drupal_strtolower(node_get_types('name', $form['type']['#value'])),
));
}
else {
$hint = '';
}
// Add the form element to toggle if signups are allowed.
$form['signup']['signup_enabled'] = array(
'#type' => 'radios',
'#options' => $radio_options,
'#default_value' => $default_option,
'#description' => $hint . '<div class="js-hide">' . t('If disabled, all of the other signup settings will be ignored.') . '</div>',
'#prefix' => '<div class="signup-allow-radios">',
'#suffix' => '</div>',
);
// If JS is enabled, signup.css will hide all the settings on page
// load if signups aren't enabled on this node.
$settings_class = "signup-node-settings";
if ($default_option != 1) {
$settings_class .= " js-hide";
}
// Add the actual settings. We wrap this in a div to make it easy
// to use jQuery to hide these settings when signups are disabled.
drupal_add_js(drupal_get_path('module', 'signup') . '/signup.js');
drupal_add_css(drupal_get_path('module', 'signup') . '/signup.css');
$form['signup']['node_settings'] = array(
'#prefix' => '<div class="' . $settings_class . '">',
'#suffix' => '</div>',
);
$form['signup']['node_settings']['settings'] = _signup_admin_form($node);
}
}