diff --git a/core/modules/book/book.module b/core/modules/book/book.module index c034ed6..5c93d73 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -335,18 +335,29 @@ function book_node_prepare_form(NodeInterface $node, $operation, FormStateInterf } /** - * Implements hook_form_FORM_ID_alter() for node_delete_confirm(). + * Implements hook_form_alter(). * * Alters the confirm form for a single node deletion. - * - * @see node_delete_confirm() */ -function book_form_node_delete_confirm_alter(&$form, FormStateInterface $form_state) { - $node = Node::load($form['nid']['#value']); +function book_form_alter(&$form, FormStateInterface $form_state, $form_id) { + $types = \Drupal::config('book.settings')->get('allowed_types'); + $node_delete_form = FALSE; + foreach ($types as $type) { + if ($form_id == 'node_' . $type . '_delete_form') { + $node_delete_form = TRUE; + break; + } + } + if (!$node_delete_form) { + // Not a node delete form for book nodes. + return; + } + + $node = $form_state->getFormObject()->getEntity(); if (isset($node->book) && $node->book['has_children']) { $form['book_warning'] = array( - '#markup' => '

' . 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.', array('%title' => $node->label())) . '

', + '#markup' => '

' . 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.', array('%title' => $node->label())) . '

', '#weight' => -10, ); } diff --git a/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php index 3e977b1..118b108 100644 --- a/core/modules/book/src/BookManager.php +++ b/core/modules/book/src/BookManager.php @@ -438,6 +438,7 @@ public function deleteFromBook($nid) { $result = $this->bookOutlineStorage->loadBookChildren($nid); $children = $this->entityManager->getStorage('node')->loadMultiple(array_keys($result)); foreach ($children as $child) { + $child->book['bid'] = $child->id(); $this->updateOutline($child); } } diff --git a/core/modules/book/src/Tests/BookTest.php b/core/modules/book/src/Tests/BookTest.php index 60e89ab..5195b9a 100644 --- a/core/modules/book/src/Tests/BookTest.php +++ b/core/modules/book/src/Tests/BookTest.php @@ -460,7 +460,7 @@ function testBookDelete() { $nodes = $this->createBook(); $this->drupalLogin($this->adminUser); $this->drupalGet('node/' . $this->book->id() . '/delete'); - $this->assertText(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.', array('%title' => $this->book->label()))); + $this->assertRaw(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' => $this->book->label()])); // Delete parent, and visit a child page. $this->drupalPostForm('node/' . $this->book->id() . '/delete', [], t('Delete')); $this->drupalGet('node/' . $nodes[0]->id());