Skip to content

Commit

Permalink
MDL-60384 mod_book: Add a label to highlight the previous chapter
Browse files Browse the repository at this point in the history
* Added current chapter's title to the button title so it's clear where you're adding the chapter to.
* Update the behat tests to reflect the changes made to the title
  • Loading branch information
Peter authored and sarjona committed Feb 11, 2019
1 parent 9e5d41e commit 448584b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
9 changes: 9 additions & 0 deletions mod/book/edit.php
Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions mod/book/edit_form.php
Expand Up @@ -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');
Expand Down
2 changes: 2 additions & 0 deletions mod/book/lang/en/book.php
Expand Up @@ -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';
Expand Down
4 changes: 3 additions & 1 deletion mod/book/locallib.php
Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions mod/book/tests/behat/create_chapters.feature
Expand Up @@ -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 |
Expand Down Expand Up @@ -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"
8 changes: 4 additions & 4 deletions mod/book/tests/behat/reorganize_chapters.feature
Expand Up @@ -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 |
Expand Down
8 changes: 4 additions & 4 deletions mod/book/tests/behat/show_hide_chapters.feature
Expand Up @@ -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 |
Expand Down

0 comments on commit 448584b

Please sign in to comment.