diff --git a/course/format/classes/base.php b/course/format/classes/base.php index f82495e8574..268b15edec6 100644 --- a/course/format/classes/base.php +++ b/course/format/classes/base.php @@ -383,6 +383,23 @@ abstract class base { return false; } + /** + * Returns true if this course format uses activity indentation. + * + * Indentation is not supported by core formats anymore and may be deprecated in the future. + * This method will keep a default return "true" for legacy reasons but new formats should override + * it with a return false to prevent future deprecations. + * + * A message in a bottle: if indentation is finally deprecated, both behat steps i_indent_right_activity + * and i_indent_left_activity should be removed as well. Right now no core behat uses them but indentation + * is not officially deprecated so they are still available for the contrib formats. + * + * @return bool if the course format uses indentation. + */ + public function uses_indentation(): bool { + return true; + } + /** * Returns a list of sections used in the course * diff --git a/course/format/classes/output/local/content/cm.php b/course/format/classes/output/local/content/cm.php index fe6d71b0da1..59ea3b6f415 100644 --- a/course/format/classes/output/local/content/cm.php +++ b/course/format/classes/output/local/content/cm.php @@ -165,7 +165,7 @@ class cm implements renderable, templatable { 'textclasses' => $displayoptions['textclasses'], ]; - if (!empty($mod->indent)) { + if (!empty($mod->indent) && $format->uses_indentation()) { $data->indent = $mod->indent; if ($mod->indent > 15) { $data->hugeindent = true; diff --git a/course/format/classes/output/local/content/cm/controlmenu.php b/course/format/classes/output/local/content/cm/controlmenu.php index 35720d7712a..1442c798d0b 100644 --- a/course/format/classes/output/local/content/cm/controlmenu.php +++ b/course/format/classes/output/local/content/cm/controlmenu.php @@ -164,7 +164,7 @@ class controlmenu implements renderable, templatable { $format = $this->format; $mod = $this->mod; $sectionreturn = $format->get_section_number(); - if (!empty($this->displayoptions['disableindentation'])) { + if (!empty($this->displayoptions['disableindentation']) || !$format->uses_indentation()) { $indent = -1; } else { $indent = $mod->indent; diff --git a/course/format/topics/lib.php b/course/format/topics/lib.php index d4e34e8a2c5..6167d99c9fc 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 false; + } + /** * Returns the display name of the given section that the course prefers. * diff --git a/course/format/upgrade.txt b/course/format/upgrade.txt index ecf5c18a592..39cd43fc94c 100644 --- a/course/format/upgrade.txt +++ b/course/format/upgrade.txt @@ -5,6 +5,7 @@ Overview of this plugin type at http://docs.moodle.org/dev/Course_formats === 4.0 === * New core_courseformat\base::uses_course_index() to define whether the course format uses course index or not. * New core_courseformat\base::supports_components() to specify if the format is compatible with reactive components. +* New core_courseformat\base::uses_indentation() to specify if the format is compatible with activity indentation. === 3.10 === * Added the missing callback supports_ajax() to format_social. diff --git a/course/format/weeks/lib.php b/course/format/weeks/lib.php index 6770f490bf4..0721b79b89f 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 false; + } + /** * Generate the title for this section page * @return string the page title diff --git a/course/tests/behat/activities_indentation.feature b/course/tests/behat/activities_indentation.feature deleted file mode 100644 index 8ef74131f60..00000000000 --- a/course/tests/behat/activities_indentation.feature +++ /dev/null @@ -1,36 +0,0 @@ -@core @core_course @_cross_browser -Feature: Indent items on the course page - In order to create a structured view of activities - As a teacher - I need to move activities and resources to left and right - - @javascript - Scenario: Indent course items with Javascript enabled - Given the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@example.com | - | student1 | Student | 1 | student1@example.com | - And the following "courses" exist: - | fullname | shortname | format | - | Course 1 | C1 | weeks | - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | student1 | C1 | student | - And I log in as "teacher1" - And I am on "Course 1" course homepage with editing mode on - And I add a "Glossary" to section "1" and I fill the form with: - | Name | Test glossary name | - | Description | Test glossary description | - When I indent right "Test glossary name" activity - Then "#section-1 li.glossary div.mod-indent-1" "css_element" should exist - And I indent right "Test glossary name" activity - And "//li[@id='section-1']/descendant::li[contains(concat(' ', @class, ' '), ' glossary ')]/descendant::a[not(contains(concat(' ', @class, ' '), ' hidden '))]/descendant::span[normalize-space(.)='Move left']" "xpath_element" should exist - And "#section-1 li.glossary div.mod-indent-2" "css_element" should exist - And I reload the page - And "#section-1 li.glossary div.mod-indent-2" "css_element" should exist - And I indent left "Test glossary name" activity - And I indent left "Test glossary name" activity - And "#section-1 li.glossary div.mod-indent-2" "css_element" should not exist - And "#section-1 li.glossary div.mod-indent-1" "css_element" should not exist - And "//li[@id='section-1']/descendant::li[contains(concat(' ', @class, ' '), ' glossary ')]/descendant::a[not(contains(concat(' ', @class, ' '), ' hidden '))]/descendant::span[normalize-space(.)='Move left']" "xpath_element" should not exist diff --git a/course/tests/behat/course_controls.feature b/course/tests/behat/course_controls.feature index b4b0fa4d4e5..b8c22e34b22 100644 --- a/course/tests/behat/course_controls.feature +++ b/course/tests/behat/course_controls.feature @@ -2,7 +2,7 @@ Feature: Course activity controls works as expected In order to manage my course's activities As a teacher - I need to edit, hide, show and indent activities inside course sections + I need to edit, hide and show activities inside course sections # The difference between these two scenario outlines is that one is with # JS enabled and the other one with JS disabled; we can not use Background @@ -42,10 +42,6 @@ Feature: Course activity controls works as expected | Forum name | Test forum name 2 | | Description | Test forum description 2 | And "section" exist - And I indent right "Test forum name 1" activity - And "section" exist - And I indent left "Test forum name 1" activity - And "section" exist And I open "Test forum name 1" actions menu And I click on "Edit settings" "link" in the "Test forum name 1" activity And I should see "Updating Forum" @@ -111,11 +107,6 @@ Feature: Course activity controls works as expected And I click on "Delete Recent activity block" "link" And I press "Yes" And "section" exist - And "section" exist - And I indent right "Test forum name 1" activity - And "section" exist - And I indent left "Test forum name 1" activity - And "section" exist And I click on "Edit settings" "link" in the "Test forum name 1" activity And I should see "Updating Forum" And I should see "Display description on course page"