You are here

function _book_add_form_elements in Drupal 6

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

Build the common elements of the book form for the node and outline forms.

2 calls to _book_add_form_elements()
book_form_alter in modules/book/book.module
Implementation of hook_form_alter(). Adds the book fieldset to the node form.
book_outline_form in modules/book/book.pages.inc
Build the form to handle all book outline operations via the outline tab.

File

modules/book/book.module, line 361
Allows users to structure the pages of a site in a hierarchy or outline.

Code

function _book_add_form_elements(&$form, $node) {

  // Need this for AJAX.
  $form['#cache'] = TRUE;
  drupal_add_js("if (Drupal.jsEnabled) { \$(document).ready(function() { \$('#edit-book-pick-book').css('display', 'none'); }); }", 'inline');
  $form['book'] = array(
    '#type' => 'fieldset',
    '#title' => t('Book outline'),
    '#weight' => 10,
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
    '#attributes' => array(
      'class' => 'book-outline-form',
    ),
  );
  foreach (array(
    'menu_name',
    'mlid',
    'nid',
    'router_path',
    'has_children',
    'options',
    'module',
    'original_bid',
    'parent_depth_limit',
  ) as $key) {
    $form['book'][$key] = array(
      '#type' => 'value',
      '#value' => $node->book[$key],
    );
  }
  $form['book']['plid'] = _book_parent_select($node->book);
  $form['book']['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#default_value' => $node->book['weight'],
    '#delta' => 15,
    '#weight' => 5,
    '#description' => t('Pages at a given level are ordered first by weight and then by title.'),
  );
  $options = array();
  $nid = isset($node->nid) ? $node->nid : 'new';
  if (isset($node->nid) && $nid == $node->book['original_bid'] && $node->book['parent_depth_limit'] == 0) {

    // This is the top level node in a maximum depth book and thus cannot be moved.
    $options[$node->nid] = $node->title;
  }
  else {
    foreach (book_get_books() as $book) {
      $options[$book['nid']] = $book['title'];
    }
  }
  if (user_access('create new books') && ($nid == 'new' || $nid != $node->book['original_bid'])) {

    // The node can become a new book, if it is not one already.
    $options = array(
      $nid => '<' . t('create a new book') . '>',
    ) + $options;
  }
  if (!$node->book['mlid']) {

    // The node is not currently in a the hierarchy.
    $options = array(
      0 => '<' . t('none') . '>',
    ) + $options;
  }

  // Add a drop-down to select the destination book.
  $form['book']['bid'] = array(
    '#type' => 'select',
    '#title' => t('Book'),
    '#default_value' => $node->book['bid'],
    '#options' => $options,
    '#access' => (bool) $options,
    '#description' => t('Your page will be a part of the selected book.'),
    '#weight' => -5,
    '#attributes' => array(
      'class' => 'book-title-select',
    ),
    '#ahah' => array(
      'path' => 'book/js/form',
      'wrapper' => 'edit-book-plid-wrapper',
      'effect' => 'slide',
    ),
  );
}