diff --git a/mod/book/edit.php b/mod/book/edit.php index c833783d67bc1..202665260e33b 100644 --- a/mod/book/edit.php +++ b/mod/book/edit.php @@ -54,6 +54,15 @@ } $chapter->cmid = $cm->id; +// Get the previous page number. +$prevpage = $chapter->pagenum - 1; +if ($prevpage) { + $currentchapter = $DB->get_record('book_chapters', ['pagenum' => $prevpage, 'bookid' => $book->id]); + if ($currentchapter) { + $chapter->currentchaptertitle = $currentchapter->title; + } +} + $options = array('noclean'=>true, 'subdirs'=>true, 'maxfiles'=>-1, 'maxbytes'=>0, 'context'=>$context); $chapter = file_prepare_standard_editor($chapter, 'content', $options, $context, 'mod_book', 'chapter', $chapter->id); diff --git a/mod/book/edit_form.php b/mod/book/edit_form.php index 7696e99c7e628..9a8cbf4d776c0 100644 --- a/mod/book/edit_form.php +++ b/mod/book/edit_form.php @@ -48,6 +48,13 @@ function definition() { $mform->addElement('header', 'general', get_string('addafter', 'mod_book')); } + if (isset($chapter->currentchaptertitle)) { + $mform->addElement('static', 'details', + get_string('previouschapter', 'mod_book'), + $chapter->currentchaptertitle + ); + } + $mform->addElement('text', 'title', get_string('chaptertitle', 'mod_book'), array('size'=>'30')); $mform->setType('title', PARAM_RAW); $mform->addRule('title', null, 'required', null, 'client'); diff --git a/mod/book/lang/en/book.php b/mod/book/lang/en/book.php index db517c07a29de..96b376a38c2ec 100644 --- a/mod/book/lang/en/book.php +++ b/mod/book/lang/en/book.php @@ -87,6 +87,8 @@ $string['numberingoptions'] = 'Available options for chapter formatting'; $string['numberingoptions_desc'] = 'Options for displaying chapters and subchapters in the table of contents'; $string['addafter'] = 'Add new chapter'; +$string['addafterchapter'] = 'Add new chapter after "{$a->title}"'; +$string['previouschapter'] = 'Previous chapter'; $string['confchapterdelete'] = 'Do you really want to delete this chapter?'; $string['confchapterdeleteall'] = 'Do you really want to delete this chapter and all its subchapters?'; $string['top'] = 'top'; diff --git a/mod/book/locallib.php b/mod/book/locallib.php index 545a1d962d02c..e156976fde9ef 100644 --- a/mod/book/locallib.php +++ b/mod/book/locallib.php @@ -336,8 +336,10 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) { $OUTPUT->pix_icon('t/hide', get_string('hidechapter', 'mod_book', $title)), array('title' => get_string('hidechapter', 'mod_book', $titleunescaped))); } + + $buttontitle = get_string('addafterchapter', 'mod_book', ['title' => $ch->title]); $toc .= html_writer::link(new moodle_url('edit.php', array('cmid' => $cm->id, 'pagenum' => $ch->pagenum, 'subchapter' => $ch->subchapter)), - $OUTPUT->pix_icon('add', get_string('addafter', 'mod_book'), 'mod_book'), array('title' => get_string('addafter', 'mod_book'))); + $OUTPUT->pix_icon('add', $buttontitle, 'mod_book'), array('title' => $buttontitle)); $toc .= html_writer::end_tag('div'); if (!$ch->subchapter) { diff --git a/mod/book/tests/behat/create_chapters.feature b/mod/book/tests/behat/create_chapters.feature index b43910ead364e..5dce6aa23d53a 100644 --- a/mod/book/tests/behat/create_chapters.feature +++ b/mod/book/tests/behat/create_chapters.feature @@ -28,13 +28,15 @@ Feature: In a book, create chapters and sub chapters | Content | Dream is the start of a journey | And I press "Save changes" And I should see "1. Dummy first chapter" in the "Table of contents" "block" - And I click on "Add new chapter" "link" in the "Table of contents" "block" + And I click on "Add new chapter after \"Dummy first chapter\"" "link" in the "Table of contents" "block" + And I should see "Dummy first chapter" And I set the following fields to these values: | Chapter title | Dummy second chapter | | Content | The path is the second part | And I press "Save changes" And I should see "2. Dummy second chapter" in the "Table of contents" "block" - And I click on "Add new chapter" "link" in the "Table of contents" "block" + And I click on "Add new chapter after \"Dummy first chapter\"" "link" in the "Table of contents" "block" + And I should see "Dummy first chapter" And I set the following fields to these values: | Chapter title | Dummy first subchapter | | Content | The path is the second part | @@ -75,4 +77,4 @@ Feature: In a book, create chapters and sub chapters Then "Edit chapter \"1. Dummy first chapter\"" "link" should not exist in the "Table of contents" "block" And "Delete chapter \"1. Dummy first chapter\"" "link" should not exist in the "Table of contents" "block" And "Hide chapter \"1. Dummy first chapter\"" "link" should not exist in the "Table of contents" "block" - And "Add new chapter" "link" should not exist in the "Table of contents" "block" + And "Add new chapter after \"Dummy first chapter\"" "link" should not exist in the "Table of contents" "block" diff --git a/mod/book/tests/behat/reorganize_chapters.feature b/mod/book/tests/behat/reorganize_chapters.feature index 6d7c65e5f6c65..e12c109d14cad 100644 --- a/mod/book/tests/behat/reorganize_chapters.feature +++ b/mod/book/tests/behat/reorganize_chapters.feature @@ -25,24 +25,24 @@ Feature: In a book, chapters and subchapters can be rearranged | Chapter title | Originally first chapter | | Content | #1 chapter content | And I press "Save changes" - And I click on "a[href*='pagenum=1']" "css_element" + And I click on "Add new chapter after \"Originally first chapter\"" "link" And I set the following fields to these values: | Chapter title | A great second chapter | | Content | #2 chapter content | And I press "Save changes" - And I click on "a[href*='pagenum=2']" "css_element" + And I click on "Add new chapter after \"A great second chapter\"" "link" And I set the following fields to these values: | Chapter title | Second chapter, subchapter 1 | | Content | #21 subchapter content | | Subchapter | 1 | And I press "Save changes" - And I click on "a[href*='pagenum=3']" "css_element" + And I click on "Add new chapter after \"Second chapter, subchapter 1\"" "link" And I set the following fields to these values: | Chapter title | Second chapter, subchapter 2 | | Content | #22 subchapter content | | Subchapter | 1 | And I press "Save changes" - And I click on "a[href*='pagenum=4']" "css_element" + And I click on "Add new chapter after \"Second chapter, subchapter 2\"" "link" And I set the following fields to these values: | Chapter title | There aren't 2 without 3 | | Content | #3 subchapter content | diff --git a/mod/book/tests/behat/show_hide_chapters.feature b/mod/book/tests/behat/show_hide_chapters.feature index f235bccc31912..463a179bc0759 100644 --- a/mod/book/tests/behat/show_hide_chapters.feature +++ b/mod/book/tests/behat/show_hide_chapters.feature @@ -26,24 +26,24 @@ Feature: Book activity chapter visibility management | Chapter title | First chapter | | Content | First chapter | And I press "Save changes" - And I click on "a[href*='pagenum=1']" "css_element" + And I click on "Add new chapter after \"First chapter\"" "link" And I set the following fields to these values: | Chapter title | Second chapter | | Content | Second chapter | And I press "Save changes" - And I click on "a[href*='pagenum=2']" "css_element" + And I click on "Add new chapter after \"Second chapter\"" "link" And I set the following fields to these values: | Chapter title | Sub chapter | | subchapter | 1 | | Content | Sub chapter | And I press "Save changes" - And I click on "a[href*='pagenum=3']" "css_element" + And I click on "Add new chapter after \"Sub chapter\"" "link" And I set the following fields to these values: | Chapter title | Third chapter | | subchapter | 0 | | Content | Third chapter | And I press "Save changes" - And I click on "a[href*='pagenum=4']" "css_element" + And I click on "Add new chapter after \"Third chapter\"" "link" And I set the following fields to these values: | Chapter title | Fourth chapter | | Content | Fourth chapter |