You are here

function protected_node_node_type_form_alter in Protected Node 6

Same name and namespace in other branches
  1. 7 protected_node.settings.inc \protected_node_node_type_form_alter()
  2. 1.0.x protected_node.settings.inc \protected_node_node_type_form_alter()

@brief Implementation of the hook_form_alter() for node types.

This function adds a field set to each node type to let user decide whether a node type is always protected, is never protected, or is protect-able. If protect-able, then one can choose whether the protected node field set should be always open, always closed, or smart (i.e. open if the node is protected.)

@param[in,out] $form The node type form where our field set is added.

1 call to protected_node_node_type_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 676
Configuration file for the protected_node module.

Code

function protected_node_node_type_form_alter(&$form) {
  $form['protected_node'] = array(
    '#type' => 'fieldset',
    '#title' => t('Protected node settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $options = array(
    PROTECTED_NODE_PROTECTION_NEVER => t('Never protected'),
    PROTECTED_NODE_PROTECTION_PROTECTABLE => t('Protectable (default is unprotected)'),
    PROTECTED_NODE_PROTECTION_PROTECTED => t('Protectable (default is protected)'),
    PROTECTED_NODE_PROTECTION_ALWAYS => t('Always protected'),
  );
  $form['protected_node']['protected_node_protection'] = array(
    '#type' => 'radios',
    '#title' => t('Protected mode for nodes of this type'),
    '#default_value' => variable_get('protected_node_protection_' . $form['#node_type']->type, PROTECTED_NODE_PROTECTION_PROTECTABLE),
    '#options' => $options,
    '#description' => t('Select the protection mode for nodes of this type:<ul><li>Never protected &mdash; the nodes cannot be protected</li><li>Protectable &mdash; lets users choose whether the node is protected, defaults to protected or unprotected.</li><li>Always protected &mdash; the node is automatically protected, the author has no choice.</li></ul>'),
  );
  $form['protected_node']['protected_node_node_type_password_field'] = array(
    '#type' => 'password_confirm',
    '#description' => t('Enter a node type password. This password is the default for all the nodes of this type.'),
    '#size' => 20,
    '#after_build' => array(
      'protected_node_autocomplete_off',
    ),
    '#title' => t('A default (global) password for nodes of this type'),
  );

  // yeah... we're calling a Core "private" function...
  _user_password_dynamic_validation();
  $options = array(
    PROTECTED_NODE_FIELDSET_OPEN => t('Always open'),
    PROTECTED_NODE_FIELDSET_SMART => t('Smart mode (Open when protected)'),
    PROTECTED_NODE_FIELDSET_CLOSE => t('Always closed'),
  );
  $form['protected_node']['protected_node_fieldset'] = array(
    '#type' => 'radios',
    '#title' => t('How to show the protected node fieldset'),
    '#default_value' => variable_get('protected_node_fieldset_' . $form['#node_type']->type, PROTECTED_NODE_FIELDSET_SMART),
    '#options' => $options,
    '#description' => t('Select whether the "Protected node" field set should be opened or closed when editing a node.'),
  );
  $form['#validate'][] = '_protected_node_node_type_validate';
  $form['#submit'][] = '_protected_node_node_type_submit';
}