diff --git a/admin/tool/usertours/classes/external/tour.php b/admin/tool/usertours/classes/external/tour.php index 502c041815c..00460c91ec7 100644 --- a/admin/tool/usertours/classes/external/tour.php +++ b/admin/tool/usertours/classes/external/tour.php @@ -104,7 +104,7 @@ class tour extends external_api { 'tourconfig' => new external_single_structure([ 'name' => new external_value(PARAM_RAW, 'Tour Name'), 'steps' => new external_multiple_structure(self::step_structure_returns()), - 'onesteptour' => new external_value(PARAM_BOOL, 'Is a one step tour', VALUE_DEFAULT, false), + 'endtourlabel' => new external_value(PARAM_RAW, 'Label of the end tour button'), ], 'Tour config', VALUE_OPTIONAL) ]); } diff --git a/admin/tool/usertours/classes/local/forms/edittour.php b/admin/tool/usertours/classes/local/forms/edittour.php index 272267d14cc..a4f11fc80aa 100644 --- a/admin/tool/usertours/classes/local/forms/edittour.php +++ b/admin/tool/usertours/classes/local/forms/edittour.php @@ -79,6 +79,10 @@ class edittour extends \moodleform { $mform->addElement('checkbox', 'enabled', get_string('tourisenabled', 'tool_usertours')); + $mform->addElement('text', 'endtourlabel', get_string('endtourlabel', 'tool_usertours')); + $mform->setType('endtourlabel', PARAM_TEXT); + $mform->addHelpButton('endtourlabel', 'endtourlabel', 'tool_usertours'); + // Configuration. $this->tour->add_config_to_form($mform); diff --git a/admin/tool/usertours/classes/manager.php b/admin/tool/usertours/classes/manager.php index 09118782d0d..6a744fc0eb5 100644 --- a/admin/tool/usertours/classes/manager.php +++ b/admin/tool/usertours/classes/manager.php @@ -370,6 +370,7 @@ class manager { $tour->set_description($data->description); $tour->set_pathmatch($data->pathmatch); $tour->set_enabled(!empty($data->enabled)); + $tour->set_endtourlabel($data->endtourlabel); foreach (configuration::get_defaultable_keys() as $key) { $tour->set_config($key, $data->$key); diff --git a/admin/tool/usertours/classes/output/tour.php b/admin/tool/usertours/classes/output/tour.php index 1127772837e..7765e1ee968 100644 --- a/admin/tool/usertours/classes/output/tour.php +++ b/admin/tool/usertours/classes/output/tour.php @@ -60,18 +60,13 @@ class tour implements \renderable { $result = (object) [ 'name' => $this->tour->get_tour_key(), 'steps' => [], - 'onesteptour' => false, + 'endtourlabel' => $this->tour->get_endtourlabel(), ]; foreach ($this->tour->get_steps() as $step) { $result->steps[] = (new step($step))->export_for_template($output); } - // Check if its a only one step tour. - if (count($result->steps) == 1) { - $result->onesteptour = true; - } - return $result; } } diff --git a/admin/tool/usertours/classes/tour.php b/admin/tool/usertours/classes/tour.php index 08e8279d7d5..a53831e8c67 100644 --- a/admin/tool/usertours/classes/tour.php +++ b/admin/tool/usertours/classes/tour.php @@ -89,6 +89,11 @@ class tour { */ protected $enabled; + /** + * @var $endtourlabel The end tour label. + */ + protected $endtourlabel; + /** * @var $sortorder The sort order. */ @@ -187,6 +192,7 @@ class tour { if (isset($record->sortorder)) { $this->sortorder = $record->sortorder; } + $this->endtourlabel = $record->endtourlabel ?? null; $this->config = json_decode($record->configdata); $this->dirty = false; $this->steps = []; @@ -322,6 +328,36 @@ class tour { return $this; } + /** + * The end tour label for the tour. + * + * @return string + */ + public function get_endtourlabel(): string { + if ($this->endtourlabel) { + $label = $this->endtourlabel; + } else if ($this->count_steps() == 1) { + $label = get_string('endonesteptour', 'tool_usertours'); + } else { + $label = get_string('endtour', 'tool_usertours'); + } + + return $label; + } + + /** + * Set the endtourlabel of the tour to the specified value. + * + * @param string $value + * @return $this + */ + public function set_endtourlabel(string $value): tour { + $this->endtourlabel = $value; + $this->dirty = true; + + return $this; + } + /** * The link to view this tour. * @@ -389,6 +425,7 @@ class tour { 'pathmatch' => $this->pathmatch, 'enabled' => $this->enabled, 'sortorder' => $this->sortorder, + 'endtourlabel' => $this->endtourlabel, 'configdata' => json_encode($this->config), ); } diff --git a/admin/tool/usertours/db/install.xml b/admin/tool/usertours/db/install.xml index c275f46d222..30e62addf23 100644 --- a/admin/tool/usertours/db/install.xml +++ b/admin/tool/usertours/db/install.xml @@ -1,5 +1,5 @@ - @@ -12,6 +12,7 @@ + diff --git a/admin/tool/usertours/db/upgrade.php b/admin/tool/usertours/db/upgrade.php index 95782b23395..c650ef72942 100644 --- a/admin/tool/usertours/db/upgrade.php +++ b/admin/tool/usertours/db/upgrade.php @@ -36,6 +36,8 @@ use tool_usertours\tour; function xmldb_tool_usertours_upgrade($oldversion) { global $CFG, $DB; + $dbman = $DB->get_manager(); + // Automatically generated Moodle v3.6.0 release upgrade line. // Put any upgrade step following this. @@ -83,5 +85,19 @@ function xmldb_tool_usertours_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2021052508, 'tool', 'usertours'); } + if ($oldversion < 2021092300) { + // Define field endtourlabel to be added to tool_usertours_tours. + $table = new xmldb_table('tool_usertours_tours'); + $field = new xmldb_field('endtourlabel', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'sortorder'); + + // Conditionally launch add field endtourlabel. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Usertours savepoint reached. + upgrade_plugin_savepoint(true, 2021092300, 'tool', 'usertours'); + } + return true; } diff --git a/admin/tool/usertours/lang/en/tool_usertours.php b/admin/tool/usertours/lang/en/tool_usertours.php index 26215e4ff68..9b53341560d 100644 --- a/admin/tool/usertours/lang/en/tool_usertours.php +++ b/admin/tool/usertours/lang/en/tool_usertours.php @@ -49,6 +49,8 @@ $string['duplicatetour_name'] = '{$a} (copy)'; $string['editstep'] = 'Editing "{$a}"'; $string['tourisenabled'] = 'Tour is enabled'; $string['enabled'] = 'Enabled'; +$string['endtourlabel'] = 'End tour button\'s label'; +$string['endtourlabel_help'] = 'You can optionally specify a custom label for the end tour button. The default label is "Got it!" for single-step, and "End tour" for multiple-step tours.'; $string['event_tour_started'] = 'Tour started'; $string['event_tour_reset'] = 'Tour reset'; $string['event_tour_ended'] = 'Tour ended'; diff --git a/admin/tool/usertours/templates/tourstep.mustache b/admin/tool/usertours/templates/tourstep.mustache index 4856ca250b3..ba7fa536531 100644 --- a/admin/tool/usertours/templates/tourstep.mustache +++ b/admin/tool/usertours/templates/tourstep.mustache @@ -43,7 +43,7 @@ Example context (json): { "name" : "tour_activity_completion", - "onesteptour" : true, + "endtourlabel" : "Got it!", "steps": [ { "stepid": 10, @@ -68,12 +68,7 @@ diff --git a/admin/tool/usertours/tests/behat/tour_navigation.feature b/admin/tool/usertours/tests/behat/tour_navigation.feature index 22b85bd0e6a..51b9a2efc3b 100644 --- a/admin/tool/usertours/tests/behat/tour_navigation.feature +++ b/admin/tool/usertours/tests/behat/tour_navigation.feature @@ -60,3 +60,21 @@ Feature: Steps can be navigated within a tour And I should see "Next" And I click on "Next" "button" And I should see "End tour" + + @javascript + Scenario: Customised 'end tour' button text for one step tours + Given I log in as "admin" + And I add a new user tour with: + | Name | Calendar tour | + | Description | Calendar tour | + | Apply to URL match | /my/% | + | Tour is enabled | 1 | + | End tour button's label | CustomText | + And I add steps to the "Calendar tour" tour: + | targettype | Block | Title | Content | + | Block | Calendar | Calendar events | This is the calendar block | + And I change window size to "large" + And I follow "Dashboard" in the user menu + And I wait until the page is ready + And I should see "This is the calendar block" + Then I should see "CustomText" diff --git a/admin/tool/usertours/upgrade.txt b/admin/tool/usertours/upgrade.txt index 3eaa56eb7b3..78c6749faad 100644 --- a/admin/tool/usertours/upgrade.txt +++ b/admin/tool/usertours/upgrade.txt @@ -2,8 +2,8 @@ This files describes API changes in the tool_usertours code. === 4.0 === * The `tourconfig` property returned by the `tool_usertours_fetch_and_start_tour` - external method has also a `onsteptour` property to differentiate between - one step tours and multiple step tours. + external method has also an `endtourlabel` property that contains the label to be used + for the end tour button. === 3.9 === * The `tourconfig` property returned by the `tool_usertours_fetch_and_start_tour` diff --git a/admin/tool/usertours/version.php b/admin/tool/usertours/version.php index cc6b23fedab..9db80d40dd5 100644 --- a/admin/tool/usertours/version.php +++ b/admin/tool/usertours/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2021052508; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2021092300; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2021052500; // Requires this Moodle version. $plugin->component = 'tool_usertours'; // Full name of the plugin (used for diagnostics).