book_form_alter

Definition

book_form_alter(&$form, $form_state, $form_id)
drupal/modules/book/book.module, line 335

Description

Implementation of hook_form_alter().

Adds the book fieldset to the node form.

@see book_pick_book_submit() @see book_submit()

Code

function book_form_alter(&$form, $form_state, $form_id) {

  if (!empty($form['#node_edit_form'])) {
    // Add elements to the node form.
    $node = $form['#node'];

    $access = user_access('administer book outlines');
    if (!$access) {
      if (user_access('add content to books') && ((!empty($node->book['mlid']) && !empty($node->nid)) || book_type_is_allowed($node->type))) {
        // Already in the book hierarchy, or this node type is allowed.
        $access = TRUE;
      }
    }

    if ($access) {
      _book_add_form_elements($form, $node);
      $form['book']['pick-book'] = array(
        '#type' => 'submit',
        '#value' => t('Change book (update list of parents)'),
         // Submit the node form so the parent select options get updated.
         // This is typically only used when JS is disabled. Since the parent options
         // won't be changed via AJAX, a button is provided in the node form to submit
         // the form and generate options in the parent select corresponding to the
         // selected book. This is similar to what happens during a node preview.
        '#submit' => array('node_form_submit_build_node'),
        '#weight' => 20,
      );
    }
  }
}