diff --git a/course/format/classes/output/local/content/section/cmitem.php b/course/format/classes/output/local/content/section/cmitem.php index a740748672f..eebfda8bd22 100644 --- a/course/format/classes/output/local/content/section/cmitem.php +++ b/course/format/classes/output/local/content/section/cmitem.php @@ -106,7 +106,7 @@ class cmitem implements named_templatable, renderable { 'extraclasses' => $mod->extraclasses, 'cmformat' => $item->export_for_template($output), 'hasinfo' => $hasinfo, - 'indent' => $mod->indent, + 'indent' => ($format->uses_indentation()) ? $mod->indent : 0, ]; } } diff --git a/course/format/classes/output/local/state/cm.php b/course/format/classes/output/local/state/cm.php index 7d7b5e302df..11452a7cdec 100644 --- a/course/format/classes/output/local/state/cm.php +++ b/course/format/classes/output/local/state/cm.php @@ -90,7 +90,7 @@ class cm implements renderable { 'uservisible' => $cm->uservisible, 'hascmrestrictions' => $this->get_has_restrictions(), 'modname' => get_string('pluginname', 'mod_' . $cm->modname), - 'indent' => $cm->indent, + 'indent' => ($format->uses_indentation()) ? $cm->indent : 0, 'module' => $cm->modname, 'plugin' => 'mod_' . $cm->modname, ]; diff --git a/course/format/topics/db/upgrade.php b/course/format/topics/db/upgrade.php index a4c48885b4d..5cdcd636e1e 100644 --- a/course/format/topics/db/upgrade.php +++ b/course/format/topics/db/upgrade.php @@ -42,5 +42,16 @@ function xmldb_format_topics_upgrade($oldversion) { // Automatically generated Moodle v4.1.0 release upgrade line. // Put any upgrade step following this. + if ($oldversion < 2023030700) { + // For sites migrating from 4.0.x or 4.1.x where the indentation was removed, + // we are disabling 'indentation' value by default. + if ($oldversion >= 2022041900) { + set_config('indentation', 0, 'format_topics'); + } else { + set_config('indentation', 1, 'format_topics'); + } + upgrade_plugin_savepoint(true, 2023030700, 'format', 'topics'); + } + return true; } diff --git a/course/format/topics/lang/en/format_topics.php b/course/format/topics/lang/en/format_topics.php index eaed84a6e41..9af90f35538 100644 --- a/course/format/topics/lang/en/format_topics.php +++ b/course/format/topics/lang/en/format_topics.php @@ -36,3 +36,5 @@ $string['page-course-view-topics-x'] = 'Any course page in topics format'; $string['hidefromothers'] = 'Hide topic'; $string['showfromothers'] = 'Show topic'; $string['privacy:metadata'] = 'The Topics format plugin does not store any personal data.'; +$string['indentation'] = 'Allow indentation on course page'; +$string['indentation_help'] = 'Allow teachers, and other users with the manage activities capability, to indent items on the course page.'; diff --git a/course/format/topics/lib.php b/course/format/topics/lib.php index a2f5843ef3e..3e099ee003c 100644 --- a/course/format/topics/lib.php +++ b/course/format/topics/lib.php @@ -50,6 +50,10 @@ class format_topics extends core_courseformat\base { return true; } + public function uses_indentation(): bool { + return (get_config('format_topics', 'indentation')) ? true : false; + } + /** * Returns the display name of the given section that the course prefers. * diff --git a/course/format/topics/settings.php b/course/format/topics/settings.php new file mode 100644 index 00000000000..6239705b869 --- /dev/null +++ b/course/format/topics/settings.php @@ -0,0 +1,34 @@ +. + +/** + * Settings for format_topics + * + * @package format_topics + * @copyright 2020 Amaia Anabitarte + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +if ($ADMIN->fulltree) { + $settings->add(new admin_setting_configcheckbox( + 'format_topics/indentation', + new lang_string('indentation', 'format_topics'), + new lang_string('indentation_help', 'format_topics'), + 1 + )); +} diff --git a/course/format/topics/version.php b/course/format/topics/version.php index 9815bec1ff5..cf81cef30d1 100644 --- a/course/format/topics/version.php +++ b/course/format/topics/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2022112800; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2023030700; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2022111800; // Requires this Moodle version. $plugin->component = 'format_topics'; // Full name of the plugin (used for diagnostics). diff --git a/course/format/weeks/db/upgrade.php b/course/format/weeks/db/upgrade.php index 59c11c2db0f..81e850d0591 100644 --- a/course/format/weeks/db/upgrade.php +++ b/course/format/weeks/db/upgrade.php @@ -42,5 +42,16 @@ function xmldb_format_weeks_upgrade($oldversion) { // Automatically generated Moodle v4.1.0 release upgrade line. // Put any upgrade step following this. + if ($oldversion < 2023030700) { + // For sites migrating from 4.0.x or 4.1.x where the indentation was removed, + // we are disabling 'indentation' value by default. + if ($oldversion >= 2022041900) { + set_config('indentation', 0, 'format_weeks'); + } else { + set_config('indentation', 1, 'format_weeks'); + } + upgrade_plugin_savepoint(true, 2023030700, 'format', 'weeks'); + } + return true; } diff --git a/course/format/weeks/lang/en/format_weeks.php b/course/format/weeks/lang/en/format_weeks.php index a649eb40ac6..4652efc0e7e 100644 --- a/course/format/weeks/lang/en/format_weeks.php +++ b/course/format/weeks/lang/en/format_weeks.php @@ -39,3 +39,5 @@ $string['showfromothers'] = 'Show week'; $string['automaticenddate'] = 'Calculate the end date from the number of sections'; $string['automaticenddate_help'] = 'If enabled, the end date for the course will be automatically calculated from the number of sections and the course start date.'; $string['privacy:metadata'] = 'The Weekly format plugin does not store any personal data.'; +$string['indentation'] = 'Allow indentation on course page'; +$string['indentation_help'] = 'Allow teachers, and other users with the manage activities capability, to indent items on the course page.'; diff --git a/course/format/weeks/lib.php b/course/format/weeks/lib.php index 88d8638dd59..a655ff3a474 100644 --- a/course/format/weeks/lib.php +++ b/course/format/weeks/lib.php @@ -49,6 +49,10 @@ class format_weeks extends core_courseformat\base { return true; } + public function uses_indentation(): bool { + return (get_config('format_weeks', 'indentation')) ? true : false; + } + /** * Generate the title for this section page * @return string the page title diff --git a/course/format/weeks/settings.php b/course/format/weeks/settings.php new file mode 100644 index 00000000000..9ffff443c1f --- /dev/null +++ b/course/format/weeks/settings.php @@ -0,0 +1,34 @@ +. + +/** + * Settings for format_weeks + * + * @package format_weeks + * @copyright 2020 Amaia Anabitarte + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +if ($ADMIN->fulltree) { + $settings->add(new admin_setting_configcheckbox( + 'format_weeks/indentation', + new lang_string('indentation', 'format_weeks'), + new lang_string('indentation_help', 'format_weeks'), + 1 + )); +} diff --git a/course/format/weeks/version.php b/course/format/weeks/version.php index 616cea5dddf..0eb6deb81ee 100644 --- a/course/format/weeks/version.php +++ b/course/format/weeks/version.php @@ -25,6 +25,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2022112800; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2023030700; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2022111800; // Requires this Moodle version. $plugin->component = 'format_weeks'; // Full name of the plugin (used for diagnostics). diff --git a/course/tests/behat/course_controls.feature b/course/tests/behat/course_controls.feature index fddf59a476c..f858d1c9aed 100644 --- a/course/tests/behat/course_controls.feature +++ b/course/tests/behat/course_controls.feature @@ -178,3 +178,29 @@ Feature: Course activity controls works as expected | courseformat | | topics | | weeks | + + @javascript + Scenario Outline: Admins could disable indentation + Given the following "courses" exist: + | fullname | shortname | format | coursedisplay | numsections | startdate | + | Course 1 | C1 | | | 5 | 0 | + And the following "activities" exist: + | activity | name | intro | course | idnumber | + | forum | Test forum name | Test forum description | C1 | forum1 | + And I log in as "admin" + And I am on "Course 1" course homepage with editing mode on + And I open "Test forum name" actions menu + And "Move right" "link" should be visible + And "Move left" "link" should not be visible + And I click on "Move right" "link" in the "Test forum name" activity + When the following config values are set as admin: + | indentation | 0 | format_ | + And I am on "Course 1" course homepage with editing mode on + And I open "Test forum name" actions menu + Then "Move right" "link" should not exist + And "Move left" "link" should not exist + + Examples: + | courseformat | + | topics | + | weeks | diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index 3a25d9b0700..a36a867ce5e 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -23,6 +23,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use \core_external\external_api; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -2730,13 +2732,19 @@ class externallib_test extends externallib_advanced_testcase { // Expect to receive all the fields. $this->assertCount(41, $result['courses'][0]); // Check default values for course format topics. - $this->assertCount(2, $result['courses'][0]['courseformatoptions']); + $this->assertCount(3, $result['courses'][0]['courseformatoptions']); foreach ($result['courses'][0]['courseformatoptions'] as $option) { - if ($option['name'] == 'hiddensections') { - $this->assertEquals(1, $option['value']); - } else { - $this->assertEquals('coursedisplay', $option['name']); - $this->assertEquals(0, $option['value']); + switch ($option['name']) { + case 'hiddensections': + $this->assertEquals(1, $option['value']); + break; + case 'coursedisplay': + $this->assertEquals(0, $option['value']); + break; + case 'indentation': + $this->assertEquals(1, $option['value']); + break; + default: } }