function book_form_node_confirm_form_alter

Same name and namespace in other branches
  1. 9 core/modules/book/book.module \book_form_node_confirm_form_alter()
  2. 8.9.x core/modules/book/book.module \book_form_node_confirm_form_alter()
  3. 10 core/modules/book/book.module \book_form_node_confirm_form_alter()

Implements hook_form_BASE_FORM_ID_alter() for \Drupal\node\Form\NodeDeleteForm.

Alters the confirm form for a single node deletion.

File

core/modules/book/book.module, line 331

Code

function book_form_node_confirm_form_alter(&$form, FormStateInterface $form_state) {
    // Only need to alter the delete operation form.
    if ($form_state->getFormObject()
        ->getOperation() !== 'delete') {
        return;
    }
    
    /** @var \Drupal\node\NodeInterface $node */
    $node = $form_state->getFormObject()
        ->getEntity();
    if (!book_type_is_allowed($node->getType())) {
        // Not a book node.
        return;
    }
    if (isset($node->book) && $node->book['has_children']) {
        $form['book_warning'] = [
            '#markup' => '<p>' . t('%title is part of a book outline, and has associated child pages. If you proceed with deletion, the child pages will be relocated automatically.', [
                '%title' => $node->label(),
            ]) . '</p>',
            '#weight' => -10,
        ];
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.