You are here

function private_form_alter in Private 7.2

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

Implements hook_form_alter().

This module adds a simple checkbox to the node to edit the private setting.

File

./private.module, line 171
A tremendously simple access control module -- it allows users to mark individual nodes as private; users with 'access private content' perms can read these nodes, while others cannot.

Code

function private_form_alter(&$form, &$form_state, $form_id) {
  if (!empty($form['#node_edit_form'])) {
    $node = $form['#node'];

    // Won't have the ->private field set when creating a new node.
    private_get_default($node);
    $form['privacy'] = array(
      '#type' => 'fieldset',
      '#access' => user_access('mark content as private'),
      '#title' => t('Privacy options'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#group' => 'additional_settings',
      '#attributes' => array(
        'class' => array(
          'node-form-private',
        ),
      ),
      '#attached' => array(
        'js' => array(
          drupal_get_path('module', 'private') . '/private.node.js',
        ),
      ),
      '#weight' => 95,
    );
    $form['privacy']['private'] = array(
      '#type' => 'checkbox',
      '#title' => t('Private'),
      '#attributes' => array(
        'title' => t('When checked, only users with proper access permissions will be able to see this post.'),
      ),
      '#default_value' => $node->private,
      '#disabled' => $node->privateLocked,
    );
  }
}