-
Notifications
You must be signed in to change notification settings - Fork 6
/
Events.php
56 lines (50 loc) · 1.67 KB
/
Events.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace acmeCorp\humhub\modules\exampleBasic;
use humhub\modules\admin\permissions\ManageModules;
use humhub\modules\admin\widgets\AdminMenu;
use humhub\modules\ui\menu\MenuLink;
use humhub\widgets\TopMenu;
use Yii;
use yii\base\Event;
class Events
{
/**
* Defines what to do when the top menu is initialized.
*
* @param $event
*
* @return void
*/
public static function onTopMenuInit($event): void
{
/** @var TopMenu $topMenuWidget */
$topMenuWidget = $event->sender;
$topMenuWidget->addEntry(new MenuLink([
'label' => Yii::t('ExampleBasicModule.base', 'Example'),
'icon' => 'anchor',
'url' => ['/example-basic/index'],
'sortOrder' => 99999,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'example-basic' && Yii::$app->controller->id == 'index'),
]));
}
/**
* Defines what to do if admin menu is initialized.
*
* @param $event Event
*
* @return void
*/
public static function onAdminMenuInit($event): void
{
/** @var AdminMenu $adminMenuWidget */
$adminMenuWidget = $event->sender;
$adminMenuWidget->addEntry(new MenuLink([
'label' => Yii::t('ExampleBasicModule.base', 'Example'),
'url' => ['/example-basic/admin'],
'icon' => 'info-circle',
'sortOrder' => 1000,
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'example-basic' && Yii::$app->controller->id == 'admin'),
'isVisible' => Yii::$app->user->can(ManageModules::class),
]));
}
}