Community Documentation

book_form

5 book.module book_form(&$node)

Implementation of hook_form().

File

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

Code

<?php
function book_form(&$node) {
  $type = node_get_types('type', $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 &lt;top-level&gt; is an independent, top-level book.') : t('The parent that this page belongs in.'),
    );
  }

  $form['title'] = array(
    '#type' => 'textfield', 
    '#title' => check_plain($type->title_label), 
    '#required' => TRUE, 
    '#default_value' => $node->title, 
    '#weight' => -5,
  );
  $form['body_filter']['body'] = array(
    '#type' => 'textarea', 
    '#title' => check_plain($type->body_label), 
    '#default_value' => $node->body, 
    '#rows' => 20, 
    '#required' => TRUE,
  );
  $form['body_filter']['format'] = filter_form($node->format);

  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 preserve the node weight; otherwise
    // we use 0 as the default for new pages
    $form['weight'] = array(
      '#type' => 'value', 
      '#value' => isset($node->weight) ? $node->weight : 0,
    );
  }

  return $form;
}
?>
Login or register to post comments