function protected_node_node_form_alter in Protected Node 6
Same name and namespace in other branches
- 7 protected_node.settings.inc \protected_node_node_form_alter()
- 1.0.x protected_node.settings.inc \protected_node_node_form_alter()
Actual implementation of the protected_node_form_alter() function.
It was moved here to optimize the module (so the .module is smaller) This is really only necessary when some edits a node.
@param[in,out] $form The form to be altered with the protected node field set.
1 call to protected_node_node_form_alter()
- protected_node_form_alter in ./
protected_node.module - Implementation of hook_form_alter(). @link http://api.drupal.org/api/function/hook_form_alter/6
File
- ./
protected_node.settings.inc, line 99 - Configuration file for the protected_node module.
Code
function protected_node_node_form_alter(&$form) {
$protection = variable_get('protected_node_protection_' . $form['type']['#value'], PROTECTED_NODE_PROTECTION_PROTECTABLE);
if ($protection == PROTECTED_NODE_PROTECTION_NEVER) {
// never protecting, do nothing
return;
}
// try to avoid pre-filled password forms
$form['#attributes']['autocomplete'] = 'off';
$node_type = node_get_types('type', $form['type']['#value']);
$fieldset_mode = variable_get('protected_node_fieldset_' . $node_type->type, PROTECTED_NODE_FIELDSET_SMART);
switch ($fieldset_mode) {
case PROTECTED_NODE_FIELDSET_OPEN:
$collapsed = FALSE;
break;
case PROTECTED_NODE_FIELDSET_CLOSE:
$collapsed = TRUE;
break;
default:
//case PROTECTED_NODE_FIELDSET_SMART:
if ($protection == PROTECTED_NODE_PROTECTION_ALWAYS || $protection == PROTECTED_NODE_PROTECTION_PROTECTED && empty($form['nid']['#value'])) {
$collapsed = FALSE;
}
else {
$collapsed = empty($form['#node']->protected_node_is_protected);
}
break;
}
$form['protected_node'] = array(
'#type' => 'fieldset',
'#description' => t('By selecting the checkbox below you password protect this page. Unless you are using the global password feature, you want to enter a password in this form.'),
'#title' => t('Password protect this @node', array(
'@node' => $node_type->name,
)),
'#collapsible' => TRUE,
'#collapsed' => $collapsed,
);
if ($protection == PROTECTED_NODE_PROTECTION_ALWAYS) {
// always protected, don't show anything to the user
$form['protected_node']['protected_node_is_protected'] = array(
'#type' => 'value',
'#value' => TRUE,
);
}
else {
// define the current default value
if (empty($form['nid']['#value'])) {
// a new node is being created, use the protection mode
// to determine the default
// (no need to test for NEVER, we're already out of this function in that case;
// no need to test for ALWAYS, we went through the previous level if() in that
// case.)
$protected = $protection == PROTECTED_NODE_PROTECTION_PROTECTED;
}
else {
$protected = !empty($form['#node']->protected_node_is_protected);
}
$form['protected_node']['protected_node_is_protected'] = array(
'#type' => 'checkbox',
'#title' => t('This @node is protected', array(
'@node' => $node_type->name,
)),
'#description' => t('Check here if this content should be protected by a password.'),
'#default_value' => $protected,
);
}
if (isset($form['#node']->protected_node_show_title)) {
$show_title = $form['#node']->protected_node_show_title;
}
else {
$show_title = variable_get('protected_node_show_node_titles', FALSE);
}
$form['protected_node']['protected_node_show_title'] = array(
'#type' => 'checkbox',
'#title' => t('Show Title'),
'#description' => t('Show the title to users when requesting the password.'),
'#default_value' => $show_title,
);
// define a password field unless only the global password should be used
switch (variable_get('protected_node_use_global_password', PROTECTED_NODE_PER_NODE_PASSWORD)) {
case PROTECTED_NODE_PER_NODE_PASSWORD:
case PROTECTED_NODE_PER_NODE_AND_GLOBAL_PASSWORD:
$form['protected_node']['protected_node_passwd'] = array(
'#type' => 'password_confirm',
'#description' => t('Enter the @node password here. Remember that changing the password prevents all the users who knew the old password to continue to access the page.', array(
'@node' => $node_type->name,
)),
'#size' => 20,
'#after_build' => array(
'protected_node_autocomplete_off',
),
);
if (variable_get('protected_node_show_password_strength', TRUE)) {
// yeah... we're calling a Core "private" function...
_user_password_dynamic_validation();
}
break;
}
if (variable_get('protected_node_allow_hint', FALSE)) {
if (isset($form['#node']->protected_node_hint)) {
$hint = $form['#node']->protected_node_hint;
}
else {
$hint = '';
}
$form['protected_node']['protected_node_hint'] = array(
'#type' => 'textarea',
'#title' => t('Password hint'),
'#description' => t('Enter a password hint. This information is displayed in the password form using the [node-password-hint] token.'),
'#default_value' => $hint,
'#cols' => 45,
'#rows' => 5,
);
}
// include the email box?
$width_height = variable_get('protected_node_email_box', '');
if ($width_height) {
list($width, $height) = explode('x', $width_height);
$form['protected_node']['protected_node_emails'] = array(
'#type' => 'textarea',
'#description' => t('Enter a list of email addresses separated by newlines and/or commas. At the time you save the page, each one of those users will be sent an email with a link back to this page and optionally the password.') . '<br />' . t('<strong>WARNING</strong>: for an email to be sent you MUST (1) protect the node; (2) re-enter the password; (3) publish the page.') . '<br />' . t('The password is necessary only if you used [node-password] in the email message. It is necessary to re-enter it because it is otherwise encrypted in the database.'),
'#cols' => $width,
'#rows' => $height,
);
}
}