\mod_book\event\chapter_deleted::create_from_chapter($book, $context, $chapter)->trigger();
- book_preload_chapters($book); // Fix structure.
- $DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
+ // Ensure that the book structure is correct.
+ // book_preload_chapters will fix parts including the pagenum.
- book_preload_chapters($book);
++ $chapters = book_preload_chapters($book);
+
- redirect('view.php?id='.$cm->id);
- }
++ book_add_fake_block($chapters, $chapter, $book, $cm);
- $chapters = book_preload_chapters($book);
- book_add_fake_block($chapters, $chapter, $book, $cm);
+ // Bump the book revision.
+ $DB->set_field('book', 'revision', $book->revision + 1, ['id' => $book->id]);
- echo $OUTPUT->header();
- echo $OUTPUT->heading($book->name);
+ if ($subchaptercount) {
+ $message = get_string('chapterandsubchaptersdeleted', 'mod_book', (object) [
+ 'title' => format_string($chapter->title),
+ 'subchapters' => $subchaptercount,
+ ]);
+ } else {
+ $message = get_string('chapterdeleted', 'mod_book', (object) [
+ 'title' => format_string($chapter->title),
+ ]);
+ }
- // The operation has not been confirmed yet so ask the user to do so.
- if ($chapter->subchapter) {
- $strconfirm = get_string('confchapterdelete', 'mod_book');
- } else {
- $strconfirm = get_string('confchapterdeleteall', 'mod_book');
+ redirect(new moodle_url('/mod/book/view.php', ['id' => $cm->id]), $message);
}
- echo '<br />';
- $continue = new moodle_url('/mod/book/delete.php', array('id'=>$cm->id, 'chapterid'=>$chapter->id, 'confirm'=>1));
- $cancel = new moodle_url('/mod/book/view.php', array('id'=>$cm->id, 'chapterid'=>$chapter->id));
- $title = format_string($chapter->title);
- echo $OUTPUT->confirm("<strong>$title</strong><p>$strconfirm</p>", $continue, $cancel);
- echo $OUTPUT->footer();
+ redirect(new moodle_url('/mod/book/view.php', ['id' => $cm->id]));