-
Notifications
You must be signed in to change notification settings - Fork 4
/
Events.php
87 lines (73 loc) · 2.86 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2021 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\contentBookmarks;
use humhub\modules\content\widgets\WallEntryControls;
use humhub\modules\contentBookmarks\helpers\Url;
use humhub\modules\contentBookmarks\models\filters\BookmarksContentStreamFilter;
use humhub\modules\contentBookmarks\widgets\BookmarkLink;
use humhub\modules\stream\models\WallStreamQuery;
use humhub\modules\stream\widgets\WallStreamFilterNavigation;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\user\widgets\ProfileMenu;
use Yii;
use humhub\modules\content\components\ContentActiveRecord;
class Events
{
public static function onWallEntryControlsInit($event)
{
if (Yii::$app->user->isGuest) {
return;
}
/* @var WallEntryControls $wallEntryControls */
$wallEntryControls = $event->sender;
/** @var ContentActiveRecord $record */
$record = $wallEntryControls->object;
if ($record->content->getContainer() !== null) {
$wallEntryControls->addWidget(BookmarkLink::class, ['record' => $record], ['sortOrder' => 450]);
}
}
public static function onProfileMenuInit($event)
{
if (Yii::$app->user->isGuest) {
return;
}
if (empty($event->sender->user) || $event->sender->user->id != Yii::$app->user->id) {
return;
}
/* @var ProfileMenu $profileMenu */
$profileMenu = $event->sender;
$profileMenu->addEntry(new MenuLink([
'label' => Yii::t('ContentBookmarksModule.base', 'Bookmarks'),
'url' => Url::toSavedContent($event->sender->user),
'icon' => 'bookmark',
'sortOrder' => 250,
'isActive' => MenuLink::isActiveState('content-bookmarks', 'saved'),
]));
}
public static function onStreamFilterBeforeRun($event)
{
if (Yii::$app->controller->module->id == 'content-bookmarks' &&
Yii::$app->controller->id == 'saved' &&
Yii::$app->controller->action->id == 'index') {
// Don't display the filter on the page with already filtered contents
return;
}
/* @var $wallFilterNavigation WallStreamFilterNavigation */
$wallFilterNavigation = $event->sender;
$wallFilterNavigation->addFilter([
'id' => BookmarksContentStreamFilter::FILTER_BOOKMARKED,
'title' => Yii::t('ContentBookmarksModule.base', 'Bookmarked'),
'sortOrder' => 250,
], WallStreamFilterNavigation::FILTER_BLOCK_BASIC);
}
public static function onStreamFilterBeforeFilter($event)
{
/* @var $streamQuery WallStreamQuery */
$streamQuery = $event->sender;
$streamQuery->addFilterHandler(BookmarksContentStreamFilter::class);
}
}