forked from humhub/custom-pages
/
Events.php
70 lines (59 loc) · 2.6 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace humhub\modules\custom_pages;
use Yii;
use yii\helpers\Url;
use humhub\modules\custom_pages\models\CustomPage;
/**
* CustomPagesEvents
*
* @author luke
*/
class Events extends \yii\base\Object
{
public static function onAdminMenuInit($event)
{
$event->sender->addItem(array(
'label' => Yii::t('CustomPagesModule.base', 'Custom Pages'),
'url' => Url::to(['/custom_pages/admin']),
'group' => 'manage',
'icon' => '<i class="fa fa-file-o"></i>',
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'custom_pages' && Yii::$app->controller->id == 'admin'),
'sortOrder' => 300,
));
// Check for Admin Menu Pages to insert
}
public static function onTopMenuInit($event)
{
foreach (CustomPage::findAll(['navigation_class' => CustomPage::NAV_CLASS_TOPNAV]) as $page) {
// Admin only
if ($page->admin_only == 1 && !Yii::$app->user->isAdmin()) {
continue;
}
$event->sender->addItem(array(
'label' => $page->title,
'url' => Url::to(['/custom_pages/view', 'id' => $page->id]),
'target' => ($page->type == CustomPage::TYPE_LINK) ? '_blank' : '',
'icon' => '<i class="fa ' . $page->icon . '"></i>',
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'custom_pages' && Yii::$app->controller->id == 'view' && Yii::$app->request->get('id') == $page->id),
'sortOrder' => ($page->sort_order != '') ? $page->sort_order : 1000,
));
}
}
public static function onAccountMenuInit($event)
{
foreach (CustomPage::findAll(['navigation_class' => CustomPage::NAV_CLASS_ACCOUNTNAV]) as $page) {
// Admin only
if ($page->admin_only == 1 && !Yii::$app->user->isAdmin()) {
continue;
}
$event->sender->addItem(array(
'label' => $page->title,
'url' => Url::to(['/custom_pages/view', 'id' => $page->id]),
'target' => ($page->type == CustomPage::TYPE_LINK) ? '_blank' : '',
'icon' => '<i class="fa ' . $page->icon . '"></i>',
'isActive' => (Yii::$app->controller->module && Yii::$app->controller->module->id == 'custom_pages' && Yii::$app->controller->id == 'view' && Yii::$app->request->get('id') == $page->id),
'sortOrder' => ($page->sort_order != '') ? $page->sort_order : 1000,
));
}
}
}