From 966f3548ae6a92ad82728665a7d73b73ed0d0021 Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Sat, 19 Aug 2023 11:28:46 +0200 Subject: [PATCH 1/2] MDL-70972 format_singleactivity: Show activities when creating course Co-authored-by: Laurent David --- course/format/singleactivity/lib.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/course/format/singleactivity/lib.php b/course/format/singleactivity/lib.php index 6a2dd522006..7d5174744e7 100644 --- a/course/format/singleactivity/lib.php +++ b/course/format/singleactivity/lib.php @@ -167,7 +167,16 @@ class format_singleactivity extends core_courseformat\base { foreach (array_keys($availabletypes) as $activity) { $capability = "mod/{$activity}:addinstance"; if (!has_capability($capability, $testcontext)) { - unset($availabletypes[$activity]); + if (!$this->categoryid) { + unset($availabletypes[$activity]); + } else { + // We do not have a course yet, so we guess if the user will have the capability to add the activity after + // creating the course. + $categorycontext = \context_coursecat::instance($this->categoryid); + if (!guess_if_creator_will_have_course_capability($capability, $categorycontext)) { + unset($availabletypes[$activity]); + } + } } } } From 8c7892ceff0e174fac807e7fd60556cedcd594de Mon Sep 17 00:00:00 2001 From: Philipp Memmel Date: Tue, 4 Jun 2024 06:29:05 +0000 Subject: [PATCH 2/2] MDL-70972 format_singleactivity: Apply new behavior to behat test --- .../format/singleactivity/tests/behat/create_course.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/course/format/singleactivity/tests/behat/create_course.feature b/course/format/singleactivity/tests/behat/create_course.feature index abce67e9eca..ed56a9005a6 100644 --- a/course/format/singleactivity/tests/behat/create_course.feature +++ b/course/format/singleactivity/tests/behat/create_course.feature @@ -21,7 +21,6 @@ Feature: Courses can be created in Single Activity mode | moodle/course:manageactivities | allow | | moodle/course:viewparticipants | allow | | moodle/role:assign | allow | - | mod/quiz:addinstance | allow | When I log in as "kevin" And I am on site homepage And I press "Add a new course" @@ -31,6 +30,7 @@ Feature: Courses can be created in Single Activity mode | Format | Single activity format | And I press "Update format" Then I should see "Quiz" in the "Type of activity" "field" - And I should not see "Forum" in the "Type of activity" "field" + And I should see "Forum" in the "Type of activity" "field" + And I set the field "Type of activity" to "Quiz" And I press "Save and display" And I should see "Adding a new Quiz"