From 38b9eb2653b1dcb8b3d5bcac9a1ef6c0f16de283 Mon Sep 17 00:00:00 2001 From: ferran Date: Tue, 13 May 2025 15:32:15 +0200 Subject: [PATCH] MDL-85404 format_social: allow subsections in social activities --- .../templates/blocksection.mustache | 4 +++- .../tests/behat/edit_activities.feature | 17 +++++++++++++++++ course/format/social/lib.php | 16 ++++++++-------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/blocks/social_activities/templates/blocksection.mustache b/blocks/social_activities/templates/blocksection.mustache index 56b995818b7..3a466b75237 100644 --- a/blocks/social_activities/templates/blocksection.mustache +++ b/blocks/social_activities/templates/blocksection.mustache @@ -66,7 +66,9 @@ {{! The block should be fast to load, we only load the editor when needed.}} {{#editing}} require(['core_courseformat/local/content'], function(component) { - component.init('block_social_activities_section', {}); + // We want to include both block content and block footer in the selector + // because the footer has the add activity button. + component.init('.block_social_activities', {}); }); {{/editing}} {{/js}} diff --git a/blocks/social_activities/tests/behat/edit_activities.feature b/blocks/social_activities/tests/behat/edit_activities.feature index 9e223a17595..613d9fb8118 100644 --- a/blocks/social_activities/tests/behat/edit_activities.feature +++ b/blocks/social_activities/tests/behat/edit_activities.feature @@ -139,3 +139,20 @@ Feature: Edit activities in social activities block And I open "Social forum" actions menu And "Move right" "link" should be visible And "Move left" "link" should not be visible + + @javascript + Scenario: Social activities block can have subsections + Given the following "activity" exists: + | activity | assign | + | course | C1 | + | name | Assignment name | + | section | 0 | + Given I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + And I click on "Add content" "button" in the ".block_social_activities .footer" "css_element" + And I click on "Subsection" "link" in the ".dropdown-menu.show" "css_element" + Then I should see "New subsection" in the "Social activities" "block" + And I open "Assignment name" actions menu + And I click on "Move" "link" in the "Assignment name" activity + And I click on "New subsection" "link" in the "Move activity" "dialogue" + Then I should see "Assignment name" in the "New subsection" "section" diff --git a/course/format/social/lib.php b/course/format/social/lib.php index f2f2778453e..a620deacc58 100644 --- a/course/format/social/lib.php +++ b/course/format/social/lib.php @@ -151,6 +151,11 @@ class format_social extends core_courseformat\base { #[\Override] public function get_section_name($section) { + $section = $this->get_section($section); + if ($section->is_delegated()) { + return $section->name; + } + // Social format only uses one section inside the social activities block. return get_string('socialactivities', 'format_social'); } @@ -164,13 +169,6 @@ class format_social extends core_courseformat\base { return 0; } - - #[\Override] - public function get_max_sections() { - // Social ony uses one section. - return 1; - } - /** * Returns if a specific section is visible to the current user. * @@ -184,6 +182,8 @@ class format_social extends core_courseformat\base { #[\Override] public function is_section_visible(section_info $section): bool { $visible = parent::is_section_visible($section); - return $visible && $section->section == 0; + // Social format does only use section 0 as a normal section. + // Any other included section should be a delegated one (subsections). + return $visible && ($section->sectionnum == 0 || $section->is_delegated()); } }