This commit is contained in:
Markos Gogoulos
2026-03-06 17:56:27 +02:00
parent 583a8c4512
commit 90b480b4f8
3 changed files with 0 additions and 125 deletions

View File

@@ -1,49 +0,0 @@
<?php
/**
* Hook listener for filter_mediacms navigation hooks (Moodle 4.3+)
*
* @package filter_mediacms
* @copyright 2026 MediaCMS
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace filter_mediacms;
/**
* Extends the primary (top) navigation bar with a My Media link.
*/
class hook_listener {
/**
* Called by the \core\hook\navigation\primary_extend hook.
* Adds the My Media link to the primary nav bar when placement = 'top'.
*/
public static function extend_primary_navigation(
\core\hook\navigation\primary_extend $hook
): void {
$placement = get_config('filter_mediacms', 'mymedia_placement');
if ($placement !== 'top') {
return;
}
if (!isloggedin() || isguestuser()) {
return;
}
$url = new \moodle_url('/filter/mediacms/my_media.php');
$node = \navigation_node::create(
get_string('mymedia', 'filter_mediacms'),
$url,
\navigation_node::TYPE_CUSTOM,
null,
'mediacms_mymedia',
new \pix_icon('i/media', '')
);
$primarynav = $hook->get_primarynav();
if ($primarynav === null) {
return;
}
$primarynav->add_node($node);
}
}

View File

@@ -1,72 +1,8 @@
<?php
/**
* Navigation callbacks for filter_mediacms
*
* @package filter_mediacms
* @copyright 2026 MediaCMS
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Add My Media to the global / flat navigation (nav drawer).
* Fires on every page when placement is set to 'top'.
* In Moodle 4.x Boost the nav drawer is opened via the hamburger icon
* and the node appears as a top-level item alongside Home / My courses.
*/
function filter_mediacms_extend_navigation(global_navigation $navigation): void {
$placement = get_config('filter_mediacms', 'mymedia_placement');
if ($placement !== 'top') {
return;
}
if (!isloggedin() || isguestuser()) {
return;
}
$url = new moodle_url('/filter/mediacms/my_media.php');
$node = navigation_node::create(
get_string('mymedia', 'filter_mediacms'),
$url,
navigation_node::TYPE_CUSTOM,
null,
'mediacms_mymedia',
new pix_icon('i/media', '')
);
// showinflatnavigation = true makes it visible in the Boost nav drawer.
$node->showinflatnavigation = true;
$navigation->add_node($node);
}
/**
* Add My Media to the user account / settings navigation.
* Fires when placement is set to 'user'.
* In Moodle 4.x Boost this section is reachable via avatar → Preferences.
*/
function filter_mediacms_extend_navigation_user_settings(
navigation_node $navigation,
stdClass $user,
context_user $usercontext,
stdClass $course,
context_course $coursecontext
): void {
$placement = get_config('filter_mediacms', 'mymedia_placement');
if ($placement !== 'user') {
return;
}
if (!isloggedin() || isguestuser()) {
return;
}
$url = new moodle_url('/filter/mediacms/my_media.php');
$navigation->add(
get_string('mymedia', 'filter_mediacms'),
$url,
navigation_node::TYPE_SETTING,
null,
'mediacms_mymedia',
new pix_icon('i/media', '')
);
}

View File

@@ -39,16 +39,4 @@ if ($ADMIN->fulltree) {
0,
$ltioptions
));
// My Media link placement.
$settings->add(new admin_setting_configselect(
'filter_mediacms/mymedia_placement',
get_string('mymedia_placement', 'filter_mediacms'),
get_string('mymedia_placement_desc', 'filter_mediacms'),
'top',
[
'top' => get_string('mymedia_placement_top', 'filter_mediacms'),
'user' => get_string('mymedia_placement_user', 'filter_mediacms'),
]
));
}