forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-71823 user: Add hook for extending user menu
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
Submodule envbar
added at
208168
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
namespace core_user\hook; | ||
|
||
/** | ||
* Hook to modify user menu. | ||
* | ||
* @package core | ||
* @copyright 2024 Guillaume Barat <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @property-read \renderer_base $renderer The page renderer object | ||
*/ | ||
#[\core\attribute\tags('user')] | ||
#[\core\attribute\label('Allows plugins to add any elements to the user menu')] | ||
final class update_navigation_menuuser { | ||
/** | ||
* Hook to modify user menu. | ||
* | ||
*/ | ||
public function __construct( | ||
public array $navitems = [], | ||
) { | ||
} | ||
|
||
/** | ||
* | ||
* @param null|array $output | ||
*/ | ||
public function add_navitems(?array $output): void { | ||
if ($output) { | ||
$this->navitems = $output; | ||
} | ||
} | ||
|
||
/** | ||
* Returns a class with the deatil for the menu. | ||
* | ||
* @return array | ||
*/ | ||
public function get_navitems(): array { | ||
return $this->navitems; | ||
} | ||
|
||
/** | ||
* Find all the navigation item to add. | ||
*/ | ||
public function find_item_navigation(): void { | ||
$pluginswithfunction = get_plugins_with_function(function: 'update_navigation_menuuser'); | ||
foreach ($pluginswithfunction as $plugins) { | ||
foreach ($plugins as $function) { | ||
$menuitem = $function(); | ||
if (is_array($menuitem)) { | ||
$this->add_navitems($menuitem); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters