+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class editmode extends external_api {
+
+ /**
+ * Description of the parameters suitable for the `change_editmode` function.
+ *
+ * @return external_function_parameters
+ */
+ public static function change_editmode_parameters(): external_function_parameters {
+ return new external_function_parameters(
+ [
+ 'setmode' => new external_value(PARAM_BOOL, 'Set edit mode to'),
+ 'context' => new external_value(PARAM_INT, 'Page context id')
+ ]
+ );
+ }
+
+ /**
+ * Save the image and return any warnings and the new image url
+ *
+ * @param bool $setmode the current edit mode
+ * @param int $contextid the current page context id
+ * @return array the new edit mode.
+ */
+ public static function change_editmode(bool $setmode, int $contextid): array {
+ global $USER, $PAGE;
+
+ $params = self::validate_parameters(
+ self::change_editmode_parameters(),
+ [
+ 'setmode' => $setmode,
+ 'context' => $contextid
+ ]
+ );
+
+ $context = \context_helper::instance_by_id($params['context']);
+ self::validate_context($context);
+ $PAGE->set_context($context);
+
+ if ($context->id === \context_user::instance($USER->id)->id) {
+ $PAGE->set_blocks_editing_capability('moodle/my:manageblocks');
+ }
+
+ $success = false;
+ if ($PAGE->user_allowed_editing()) {
+ $USER->editing = $setmode;
+ $success = true;
+ }
+
+ return ['success' => $success];
+ }
+
+ /**
+ * Description of the return value for the `change_editmode` function.
+ *
+ * @return external_single_structure
+ */
+ public static function change_editmode_returns(): external_single_structure {
+ $keys = [
+ 'success' => new external_value(PARAM_BOOL, 'The edit mode was changed', VALUE_REQUIRED),
+ ];
+
+ return new external_single_structure($keys, 'editmode');
+ }
+}
diff --git a/lib/db/services.php b/lib/db/services.php
index 89b5fe07e61..dff501bf9b4 100644
--- a/lib/db/services.php
+++ b/lib/db/services.php
@@ -2779,6 +2779,13 @@ $functions = array(
'type' => 'write',
'ajax' => true,
],
+ 'core_change_editmode' => [
+ 'classname' => 'core\external\editmode',
+ 'methodname' => 'change_editmode',
+ 'description' => 'Change the editing mode',
+ 'type' => 'write',
+ 'ajax' => true,
+ ],
);
$services = array(
diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php
index 39b3533350c..bcf90e423a1 100644
--- a/lib/outputrenderers.php
+++ b/lib/outputrenderers.php
@@ -2748,6 +2748,9 @@ EOD;
*/
public function edit_button(moodle_url $url) {
+ if ($this->page->theme->haseditswitch == true) {
+ return;
+ }
$url->param('sesskey', sesskey());
if ($this->page->user_is_editing()) {
$url->param('edit', 'off');
@@ -2760,6 +2763,27 @@ EOD;
return $this->single_button($url, $editstring);
}
+ /**
+ * Create a navbar switch for toggling editing mode.
+ *
+ * @return string Html containing the edit switch
+ */
+ public function edit_switch() {
+ if ($this->page->user_allowed_editing()) {
+
+ $temp = (object) [
+ 'legacyseturl' => (new moodle_url('/editmode.php'))->out(false),
+ 'pagecontextid' => $this->page->context->id,
+ 'pageurl' => $this->page->url,
+ 'sesskey' => sesskey(),
+ ];
+ if ($this->page->user_is_editing()) {
+ $temp->checked = true;
+ }
+ return $this->render_from_template('core/editswitch', $temp);
+ }
+ }
+
/**
* Returns HTML to display a simple button to close a window
*
diff --git a/lib/templates/editswitch.mustache b/lib/templates/editswitch.mustache
new file mode 100644
index 00000000000..6c368d3e954
--- /dev/null
+++ b/lib/templates/editswitch.mustache
@@ -0,0 +1,63 @@
+{{!
+ This file is part of Moodle - http://moodle.org/
+
+ Moodle is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Moodle is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Moodle. If not, see .
+}}
+{{!
+
+ @template theme_boost/editswitch
+
+ This template renders the top navbar.
+
+ Example context (json):
+ {
+ "url": "http://localhost/",
+ "sesskey": "sesskey",
+ "edit": 1,
+ "adminedit": true,
+ "checked": "",
+ "string": "Edit on"
+ }
+}}
+
+{{#js}}
+require(['core/edit_switch'], function(editSwitch) {
+ editSwitch.init('{{uniqid}}-editingswitch');
+});
+{{/js}}
diff --git a/theme/boost/templates/navbar.mustache b/theme/boost/templates/navbar.mustache
index 3afad628389..d5c6f2c0b56 100644
--- a/theme/boost/templates/navbar.mustache
+++ b/theme/boost/templates/navbar.mustache
@@ -73,5 +73,6 @@
{{> core/user_menu }}
{{/usermenu}}
+ {{{ output.edit_switch }}}
diff --git a/version.php b/version.php
index 4b53e01d492..eb0f963cf16 100644
--- a/version.php
+++ b/version.php
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2021092400.00; // YYYYMMDD = weekly release date of this DEV branch.
+$version = 2021092400.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev (Build: 20210924)'; // Human-friendly version name