forked from humhub-contrib/block-profile-changes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvents.php
62 lines (53 loc) · 1.92 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
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\blockprofilechanges;
use humhub\components\Controller;
use humhub\modules\user\widgets\AccountMenu;
use humhub\modules\user\widgets\AccountProfileMenu;
use Yii;
use yii\base\ActionEvent;
use yii\base\WidgetEvent;
use yii\helpers\Url;
use yii\web\HttpException;
class Events
{
public static function onControllerAction(ActionEvent $event)
{
/** @var Controller $controller */
$controller = $event->sender;
/** @var Module $module */
$module = Yii::$app->getModule('block-profile-changes');
if (in_array($controller->id . '.' . $event->action->id, $module->forbiddenActions)) {
$event->isValid = false;
$event->result = Yii::$app->response->redirect(['/activity/user']);
}
}
public static function onAccountMenu(WidgetEvent $event)
{
/** @var AccountMenu $accountMenu */
$accountProfileMenu = $event->sender;
/** @var Module $module */
$module = Yii::$app->getModule('block-profile-changes');
if(isset($module->removeMenuEntries['AccountMenu'])) {
foreach($module->removeMenuEntries['AccountMenu'] as $url) {
$accountProfileMenu->deleteItemByUrl(Url::to([$url]));
}
}
}
public static function onAccountProfileMenu(WidgetEvent $event)
{
/** @var AccountProfileMenu $accountProfileMenu */
$accountProfileMenu = $event->sender;
/** @var Module $module */
$module = Yii::$app->getModule('block-profile-changes');
if(isset($module->removeMenuEntries['AccountProfileMenu'])) {
foreach($module->removeMenuEntries['AccountProfileMenu'] as $url) {
$accountProfileMenu->deleteItemByUrl(Url::to([$url]));
}
}
}
}