diff --git a/classes/helper.php b/classes/helper.php index d823701..da3ea96 100644 --- a/classes/helper.php +++ b/classes/helper.php @@ -24,28 +24,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class helper { - /** - * Get the current default activity header description without rendering the full header. - * - * Calling activity_header::export_for_template() here would add completion actions as a side effect. - * - * @return string - */ - public static function get_activity_header_description(): string { - global $PAGE; - - $layoutoptions = $PAGE->layout_options['activityheader'] ?? []; - if ( - empty($layoutoptions['nodescription']) - && !empty($PAGE->activityrecord->intro) - && trim($PAGE->activityrecord->intro) - ) { - return format_module_intro($PAGE->activityname, $PAGE->activityrecord, $PAGE->cm->id); - } - - return ''; - } - /** * Render the activity header for learningmap modals. * diff --git a/classes/local/hook_callbacks.php b/classes/local/hook_callbacks.php index 54df7f5..296bd56 100644 --- a/classes/local/hook_callbacks.php +++ b/classes/local/hook_callbacks.php @@ -29,7 +29,6 @@ use core\hook\output\before_http_headers; use Exception; use mod_learningmap\cachemanager; -use mod_learningmap\helper; /** * Hook callbacks for mod_learningmap. @@ -100,8 +99,7 @@ public static function inject_backlinks_into_activity_header(before_http_headers } if ($backlinktext) { - $description = helper::get_activity_header_description(); - $PAGE->activityheader->set_description($description . $backlinktext); + $PAGE->add_header_action($backlinktext); } } catch (Exception $e) { debugging($e->getMessage()); diff --git a/lib.php b/lib.php index 7cfec58..149fbc5 100644 --- a/lib.php +++ b/lib.php @@ -440,8 +440,7 @@ function learningmap_before_http_headers() { } if ($backlinktext) { - $description = helper::get_activity_header_description(); - $PAGE->activityheader->set_description($description . $backlinktext); + $PAGE->add_header_action($backlinktext); } } catch (Exception $e) { debugging($e->getMessage()); diff --git a/styles.css b/styles.css index e90ef41..debbc43 100644 --- a/styles.css +++ b/styles.css @@ -139,10 +139,6 @@ padding-right: 0.5rem; } -.learningmap-backlink { - padding-top: 1rem; -} - .learningmap-container { width: 100%; } diff --git a/templates/backtomap.mustache b/templates/backtomap.mustache index 37aa064..7f3d5cd 100644 --- a/templates/backtomap.mustache +++ b/templates/backtomap.mustache @@ -17,7 +17,7 @@ {{! @template mod_learningmap/backtomap - Template for displaying the "back to learning map" button in activity descriptions. + Template for displaying the "back to learning map" button in the page header actions of activities. Classes required for JS: * none diff --git a/tests/mod_learningmap_backlink_cache_test.php b/tests/mod_learningmap_backlink_cache_test.php index 07f2576..f247bdd 100644 --- a/tests/mod_learningmap_backlink_cache_test.php +++ b/tests/mod_learningmap_backlink_cache_test.php @@ -182,24 +182,28 @@ public function test_backlink_generation(): void { // Test an activity that is part of the first learning map (with backlink enabled). $PAGE->set_cm($modinfo->get_cm($this->activities[0][0]->cmid)); $PAGE->set_activity_record($this->activities[0][0]); + // Simulate an activity setting its own header description (e.g. mod_assign with intro attachments). + $PAGE->activityheader->set_description('Custom activity description'); - $descriptionbefore = $PAGE->activityheader->export_for_template($OUTPUT)['description']; + $this->assertEmpty($PAGE->get_header_actions()); learningmap_before_http_headers(); - $descriptionafter = $PAGE->activityheader->export_for_template($OUTPUT)['description']; - $this->assertNotEquals($descriptionbefore, $descriptionafter); - $this->assertTrue(str_contains($descriptionafter, $this->learningmaps[0]->cmid)); + $headeractions = $PAGE->get_header_actions(); + $this->assertCount(1, $headeractions); + $this->assertTrue(str_contains($headeractions[0], $this->learningmaps[0]->cmid)); + // The description set by the activity must not be touched. + $this->assertEquals( + 'Custom activity description', + $PAGE->activityheader->export_for_template($OUTPUT)['description'] + ); // Test an activity that is part of the second learning map (with backlink disabled). $PAGE = new \moodle_page(); $PAGE->set_cm($modinfo->get_cm($this->activities[1][1]->cmid)); $PAGE->set_activity_record($this->activities[1][1]); - $descriptionbefore = $PAGE->activityheader->export_for_template($OUTPUT)['description']; learningmap_before_http_headers(); - - $descriptionafter = $PAGE->activityheader->export_for_template($OUTPUT)['description']; - $this->assertEquals($descriptionbefore, $descriptionafter); + $this->assertEmpty($PAGE->get_header_actions()); // Test an activity that is part of the second course (without any learning maps). $PAGE = new \moodle_page(); @@ -207,11 +211,8 @@ public function test_backlink_generation(): void { $PAGE->set_cm($modinfo->get_cm($this->activities[3][0]->cmid)); $PAGE->set_activity_record($this->activities[3][0]); - $descriptionbefore = $PAGE->activityheader->export_for_template($OUTPUT)['description']; learningmap_before_http_headers(); - - $descriptionafter = $PAGE->activityheader->export_for_template($OUTPUT)['description']; - $this->assertEquals($descriptionbefore, $descriptionafter); + $this->assertEmpty($PAGE->get_header_actions()); // Learningmap is invisible for the user. Backlink should not be generated. $PAGE = new \moodle_page(); @@ -219,10 +220,7 @@ public function test_backlink_generation(): void { $PAGE->set_cm($modinfo->get_cm($this->activities[2][1]->cmid)); $PAGE->set_activity_record($this->activities[2][1]); - $descriptionbefore = $PAGE->activityheader->export_for_template($OUTPUT)['description']; learningmap_before_http_headers(); - - $descriptionafter = $PAGE->activityheader->export_for_template($OUTPUT)['description']; - $this->assertEquals($descriptionbefore, $descriptionafter); + $this->assertEmpty($PAGE->get_header_actions()); } }