1 node_access_example.module node_access_example_form_alter(&$form, $form_state)

Implements hook_form_alter().

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

Related topics

File

modules/examples/node_access_example/node_access_example.module, line 374
Module file illustrating API-based node access.

Code

function node_access_example_form_alter(&$form, $form_state) {
  if (isset($form_state['build_info']['base_form_id']) && $form_state['build_info']['base_form_id'] == 'node_form') {
    $form['node_access_example'] = array(
      '#type' => 'fieldset',
      '#title' => t('Node Access Example'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#weight' => 8,
    );

    $form['node_access_example']['private'] = array(
      '#type' => 'checkbox',
      '#title' => t('Private'),
      '#description' => t('Check here if this content should be set private and only shown to privileged users.'),
      '#default_value' => isset($form['#node']->private) ? $form['#node']->private : FALSE,
    );
  }
}