Moodleのプロファイルページに画像のようにナビゲーション(Category nameの部分)を追加する場合のメモ。
プロフィールページ中にナビゲーションを表示している部分は下記になる。
user/classes/output/myprofile/manager.php
// Core components.
$components = \core_component::get_core_subsystems();
foreach ($components as $component => $directory) {
if (empty($directory)) {
continue;
}
$file = $directory . "/lib.php";
if (is_readable($file)) {
require_once($file);
$function = "core_" . $component . "_myprofile_navigation";
if (function_exists($function)) {
$function($tree, $user, $iscurrentuser, $course);
}
}
}
// Plugins.
$pluginswithfunction = get_plugins_with_function('myprofile_navigation', 'lib.php');
foreach ($pluginswithfunction as $plugins) {
foreach ($plugins as $function) {
$function($tree, $user, $iscurrentuser, $course);
}
}
ここでデフォルトだと各変数の値は下記のようになっている。自前で作成する場合は$pluginwithfunctionの方に注目することになる。
$components = array(68) {
["access"]=> NULL
["admin"]=> string(21) "/var/www/moodle/admin"
["analytics"]=> string(25) "/var/www/moodle/analytics"
["antivirus"]=> string(29) "/var/www/moodle/lib/antivirus"
["auth"]=> string(20) "/var/www/moodle/auth"
["availability"]=> string(28) "/var/www/moodle/availability"
["backup"]=> string(30) "/var/www/moodle/backup/util/ui"
["badges"]=> string(22) "/var/www/moodle/badges"
(snip)
}
$pluginwithfunction = array(4) {
["mod"]=> array(1) {
["forum"]=> string(30) "mod_forum_myprofile_navigation"
}
["report"]=> array(5) {
["insights"]=> string(36) "report_insights_myprofile_navigation"
["log"]=> string(31) "report_log_myprofile_navigation"
["outline"]=> string(35) "report_outline_myprofile_navigation"
["stats"]=> string(33) "report_stats_myprofile_navigation"
["usersessions"]=> string(40) "report_usersessions_myprofile_navigation"
}
["gradereport"]=> array(2) {
["overview"]=> string(41) "gradereport_overview_myprofile_navigation"
["user"]=> string(37) "gradereport_user_myprofile_navigation"
}
["tool"]=> array(2) {
["lp"]=> string(28) "tool_lp_myprofile_navigation"
["mobile"]=> string(32) "tool_mobile_myprofile_navigation"
}
}
プラグイン名がmod_pluginnameの場合は、lib.phpに下記のようにcategoryを作成してその中でnodeを付与する。
function mod_pluginname_myprofile_navigation(\core_user\output\myprofile\tree $tree, $user, $iscurrentuser) {
$category = new core_user\output\myprofile\category(
'catname',
'Category name'
);
$tree->add_category($category);
$node = new core_user\output\myprofile\node(
'catname',
'nodename',
'contents'
);
$tree->add_node($node);
}
参考に両クラスの初期化部分を記載しておく。
user/classes/output/myprofile/category.php
class category implements \renderable {
...
public function __construct($name, $title, $after = null, $classes = null)
...
user/classes/output/myprofile/node.php
class node implements \renderable {
...
public function __construct($parentcat, $name, $title, $after = null, $url = null, $content = null, $icon = null, $classes = null)
...