You are here

function book_form in Drupal 4

Same name and namespace in other branches
  1. 5 modules/book/book.module \book_form()

Implementation of hook_form().

File

modules/book.module, line 221
Allows users to collaboratively author a book.

Code

function book_form(&$node) {
  if ($node->nid && !$node->parent && !user_access('create new books')) {
    $form['parent'] = array(
      '#type' => 'value',
      '#value' => $node->parent,
    );
  }
  else {
    $form['parent'] = array(
      '#type' => 'select',
      '#title' => t('Parent'),
      '#default_value' => $node->parent ? $node->parent : arg(4),
      '#options' => book_toc($node->nid),
      '#weight' => -4,
      '#description' => user_access('create new books') ? t('The parent section in which to place this page.  Note that each page whose parent is <top-level> is an independent, top-level book.') : t('The parent that this page belongs in.'),
    );
  }
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#weight' => -5,
  );
  $form['body_filter']['body'] = array(
    '#type' => 'textarea',
    '#title' => t('Body'),
    '#default_value' => $node->body,
    '#rows' => 20,
    '#required' => TRUE,
  );
  $form['body_filter']['format'] = filter_form($node->format);
  $form['log'] = array(
    '#type' => 'textarea',
    '#title' => t('Log message'),
    '#weight' => 5,
    '#description' => t('An explanation of the additions or updates being made to help other authors understand your motivations.'),
  );
  if (user_access('administer nodes')) {
    $form['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight'),
      '#default_value' => $node->weight,
      '#delta' => 15,
      '#weight' => 5,
      '#description' => t('Pages at a given level are ordered first by weight and then by title.'),
    );
  }
  else {

    // If a regular user updates a book page, we create a new revision
    // authored by that user:
    $form['revision'] = array(
      '#type' => 'hidden',
      '#value' => 1,
    );
  }
  return $form;
}