book_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id)
Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\NodeForm.
Adds the book form element to the node form.
See also
File
- core/modules/book/book.module, line 136
- Allows users to create and organize related content in an outline.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | function book_form_node_form_alter(& $form , FormStateInterface $form_state , $form_id ) { $node = $form_state ->getFormObject()->getEntity(); $account = \Drupal::currentUser(); $access = $account ->hasPermission( 'administer book outlines' ); if (! $access ) { if ( $account ->hasPermission( 'add content to books' ) && ((! empty ( $node ->book[ 'bid' ]) && ! $node ->isNew()) || book_type_is_allowed( $node -> getType ()))) { // Already in the book hierarchy, or this node type is allowed. $access = TRUE; } } if ( $access ) { $collapsed = !( $node ->isNew() && ! empty ( $node ->book[ 'pid' ])); $form = \Drupal::service( 'book.manager' )->addFormElements( $form , $form_state , $node , $account , $collapsed ); // The "js-hide" class hides submit 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, '#attributes' => array ( 'class' => array ( 'js-hide' , ), ), ); $form [ '#entity_builders' ][] = 'book_node_builder' ; } } |
Please login to continue.