diff --git a/classes/external/get_cm.php b/classes/external/get_cm.php
index 084b3dba..c156d804 100644
--- a/classes/external/get_cm.php
+++ b/classes/external/get_cm.php
@@ -21,6 +21,7 @@
use core_external\external_single_structure;
use core_external\external_function_parameters;
use mod_learningmap\helper;
+
/**
* Class get_cm
*
diff --git a/classes/helper.php b/classes/helper.php
index d8237010..da3ea964 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 54df7f58..296bd56d 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/db/hooks.php b/db/hooks.php
index a3bb795c..eb8c66c6 100644
--- a/db/hooks.php
+++ b/db/hooks.php
@@ -22,6 +22,7 @@
* @author Philipp Memmel
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+
defined('MOODLE_INTERNAL') || die();
$callbacks = [
diff --git a/lib.php b/lib.php
index 7cfec58c..149fbc5f 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 e90ef417..364f0600 100644
--- a/styles.css
+++ b/styles.css
@@ -137,10 +137,7 @@
.learningmap-icon:before {
content: 'A';
padding-right: 0.5rem;
-}
-
-.learningmap-backlink {
- padding-top: 1rem;
+ vertical-align: middle;
}
.learningmap-container {
diff --git a/templates/backtomap.mustache b/templates/backtomap.mustache
index 37aa0649..bcf97246 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
@@ -35,5 +35,5 @@
}
}}
\ No newline at end of file
diff --git a/tests/mod_learningmap_backlink_cache_test.php b/tests/mod_learningmap_backlink_cache_test.php
index 07f25768..f247bddf 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());
}
}
diff --git a/tests/mod_learningmap_completion_test.php b/tests/mod_learningmap_completion_test.php
index 6bcc619e..fa48e81c 100644
--- a/tests/mod_learningmap_completion_test.php
+++ b/tests/mod_learningmap_completion_test.php
@@ -15,6 +15,7 @@
// along with Moodle. If not, see .
namespace mod_learningmap;
+
use mod_learningmap\completion\custom_completion;
defined('MOODLE_INTERNAL') || die();
diff --git a/tests/mod_learningmap_mapworker_test.php b/tests/mod_learningmap_mapworker_test.php
index ec07c98d..48569e8f 100644
--- a/tests/mod_learningmap_mapworker_test.php
+++ b/tests/mod_learningmap_mapworker_test.php
@@ -15,6 +15,7 @@
// along with Moodle. If not, see .
namespace mod_learningmap;
+
use mod_learningmap\completion\custom_completion;
/**
diff --git a/version.php b/version.php
index 6f81eb6a..9e2835ee 100644
--- a/version.php
+++ b/version.php
@@ -22,6 +22,7 @@
* @author Stefan Hanauska
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'mod_learningmap';