diff --git a/course/format/classes/output/local/content/section/cmitem.php b/course/format/classes/output/local/content/section/cmitem.php index a740748672f09..eebfda8bd2246 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 @@ public function export_for_template(\renderer_base $output): stdClass { '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 abaff473e2649..b78fe5f88636b 100644 --- a/course/format/classes/output/local/state/cm.php +++ b/course/format/classes/output/local/state/cm.php @@ -89,9 +89,9 @@ public function export_for_template(renderer_base $output): stdClass { 'sectionnumber' => $section->section, 'uservisible' => $cm->uservisible, 'hascmrestrictions' => $this->get_has_restrictions(), - 'indent' => $cm->indent, 'module' => $cm->modname, 'plugin' => 'mod_' . $cm->modname, + 'indent' => ($format->uses_indentation()) ? $cm->indent : 0, ]; // Check the user access type to this cm. diff --git a/course/format/topics/db/upgrade.php b/course/format/topics/db/upgrade.php index 5ac1908711e2d..7be52caf5a1b3 100644 --- a/course/format/topics/db/upgrade.php +++ b/course/format/topics/db/upgrade.php @@ -48,5 +48,16 @@ function xmldb_format_topics_upgrade($oldversion) { // Automatically generated Moodle v4.0.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 eaed84a6e415c..9af90f3553808 100644 --- a/course/format/topics/lang/en/format_topics.php +++ b/course/format/topics/lang/en/format_topics.php @@ -36,3 +36,5 @@ $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 a2f5843ef3e49..3e099ee003c7a 100644 --- a/course/format/topics/lib.php +++ b/course/format/topics/lib.php @@ -50,6 +50,10 @@ public function uses_course_index() { 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 0000000000000..6239705b869c0 --- /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 f0dbba08aafde..cf14b15b55f35 100644 --- a/course/format/topics/version.php +++ b/course/format/topics/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2022041900; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2023030700; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2022041200; // 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 a7f06f6ab2739..3c1eef0be20f3 100644 --- a/course/format/weeks/db/upgrade.php +++ b/course/format/weeks/db/upgrade.php @@ -48,5 +48,16 @@ function xmldb_format_weeks_upgrade($oldversion) { // Automatically generated Moodle v4.0.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 a649eb40ac600..4652efc0e7eb0 100644 --- a/course/format/weeks/lang/en/format_weeks.php +++ b/course/format/weeks/lang/en/format_weeks.php @@ -39,3 +39,5 @@ $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 88d8638dd5944..a655ff3a474d2 100644 --- a/course/format/weeks/lib.php +++ b/course/format/weeks/lib.php @@ -49,6 +49,10 @@ public function uses_course_index() { 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 0000000000000..9ffff443c1f90 --- /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 bb43f38b86402..a76cdcfef427a 100644 --- a/course/format/weeks/version.php +++ b/course/format/weeks/version.php @@ -25,6 +25,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2022041900; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2023030700; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2022041200; // 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 fee3b666f3b4d..e9d3a3c8187a6 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 e547b781f4350..ca348327bf08e 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -2725,13 +2725,19 @@ public function test_get_courses_by_field() { // 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: } }