1 book.module book_form_node_form_alter(&$form, &$form_state, $form_id)

Implements hook_form_BASE_FORM_ID_alter().

Adds the book fieldset to the node form.

See also

book_pick_book_nojs_submit()

File

core/modules/book/book.module, line 387
Allows users to create and organize related content in an outline.

Code

function book_form_node_form_alter(&$form, &$form_state, $form_id) {
  $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, $form_state, $node);
    // Since the "Book" dropdown can't trigger a form submission when
    // JavaScript is disabled, add a submit button to do that. book.admin.css hides
    // this button when JavaScript is enabled.
    $form['book']['pick-book'] = array(
      '#type' => 'submit',
      '#value' => t('Change book (update list of parents)'),
      '#submit' => array('book_pick_book_nojs_submit'),
      '#weight' => 20,
      '#attached' => array(
        'css' => array(backdrop_get_path('module', 'book') . '/css/book.admin.css'),
      ),
    );
    if (!empty($node->nid)) {
      $form['book']['actions'] = array(
        '#theme' => 'links',
        '#links' => array(),
        '#attributes' => array('class' => array('links', 'inline')),
        '#weight' => 40,
      );
      if (_book_outline_remove_access($node)) {
        $form['book']['actions']['#links']['remove'] = array(
          'title' => t('Remove from book outline'),
          'href' => 'node/' . $node->nid . '/outline-remove',
        );
      }
      if (!empty($node->book['bid']) && _book_outline_access($node)) {
        $form['book']['actions']['#links']['reorder'] = array(
          'title' => t('Reorder book pages'),
          'href' => 'admin/content/book/' . $node->book['bid'],
        );
      }
    }
  }
}