From 2830aca413630a2629cb0acce6ea35f7a46b5836 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 2 Apr 2018 04:09:35 +0000 Subject: [PATCH] MDL-60115 mod_book: Book Resource Cancel Button Redirect Bug When the user creates a book but adds no chapters, hitting cancel on the chapter creation page would redirect you right back to the same page with no explanation. This solution redirects to the course page when canceling chapter creation when no chapters are present. --- mod/book/edit.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mod/book/edit.php b/mod/book/edit.php index 09b99d44879..c833783d67b 100644 --- a/mod/book/edit.php +++ b/mod/book/edit.php @@ -61,6 +61,12 @@ $mform = new book_chapter_edit_form(null, array('chapter'=>$chapter, 'options'=> // If data submitted, then process and store. if ($mform->is_cancelled()) { + // Make sure at least one chapter exists. + $chapters = book_preload_chapters($book); + if (!$chapters) { + redirect(new moodle_url('/course/view.php', array('id' => $course->id))); // Back to course view. + } + if (empty($chapter->id)) { redirect("view.php?id=$cm->id"); } else {