You are here

function private_form_alter in Private 5

Same name and namespace in other branches
  1. 6 private.module \private_form_alter()
  2. 7.2 private.module \private_form_alter()
  3. 7 private.module \private_form_alter()

Implementation of hook_form_alter()

This module adds a simple checkbox to the node form labeled private. If the checkbox is labelled, only the node author and users with 'access private content' privileges may see it.

File

./private.module, line 145
This is an example illustrating how to restrict access to nodes based on some criterion associated with the user.

Code

function private_form_alter($form_id, &$form) {
  if ($form['#id'] == 'node-form') {
    if (user_access('mark content as private')) {
      $form['private'] = array(
        '#type' => 'checkbox',
        '#title' => t('Private'),
        '#return_value' => 1,
        '#description' => t('Check here if this content should be set private and only shown to authorized users.'),
        '#default_value' => $form['#node']->private,
      );
    }
    else {
      $form['private'] = array(
        '#type' => 'hidden',
        '#value' => $form['#node']->private,
      );
    }
  }
}