Elgg
Version master
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
engine
classes
Elgg
Notifications
RegisterSubscriptionMenuItemsHandler.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Elgg\Notifications
;
4
5
use
Elgg\Menu\MenuItems
;
6
14
class
RegisterSubscriptionMenuItemsHandler
{
15
27
public
function
__invoke
(\
Elgg
\
Event
$event) {
28
29
$result
= $event->getValue();
30
$entity
= $event->getEntityParam();
31
if
(!
$result
instanceof
MenuItems
|| !
$entity
instanceof \
ElggEntity
) {
32
return
;
33
}
34
35
if
(!
elgg_is_logged_in
()) {
36
return
;
37
}
38
39
$link_classes = [];
40
if
($event->getParam(
'name'
) ===
'title'
) {
41
$link_classes = [
42
'elgg-button'
,
43
'elgg-button-action'
,
44
];
45
}
46
47
$has_subscriptions =
$entity
->hasSubscriptions();
48
49
// subscribe
50
$subscribe_options = [
51
'name'
=>
'entity_subscribe'
,
52
'icon'
=>
'bell'
,
53
'text'
=>
elgg_echo
(
'entity:subscribe'
),
54
'href'
=>
false
,
55
'item_class'
=> $has_subscriptions ?
'hidden'
:
''
,
56
'link_class'
=> $link_classes,
57
];
58
59
// check if it makes sense to enable the subscribe button
60
$has_preferences = !empty(array_keys(array_filter(
elgg_get_logged_in_user_entity
()->getNotificationSettings())));
61
if
($has_preferences) {
62
$subscribe_options[
'href'
] =
elgg_generate_action_url
(
'entity/subscribe'
, [
63
'guid'
=>
$entity
->guid,
64
]);
65
$subscribe_options[
'data-toggle'
] =
'entity_mute'
;
66
}
else
{
67
$subscribe_options[
'link_class'
][] =
'elgg-state-disabled'
;
68
$subscribe_options[
'title'
] =
elgg_echo
(
'entity:subscribe:disabled'
);
69
}
70
71
$result
[] =
\ElggMenuItem::factory
($subscribe_options);
72
73
// mute
74
$result
[] =
\ElggMenuItem::factory
([
75
'name'
=>
'entity_mute'
,
76
'icon'
=>
'bell-slash'
,
77
'text'
=>
elgg_echo
(
'entity:mute'
),
78
'href'
=>
elgg_generate_action_url
(
'entity/mute'
, [
79
'guid'
=>
$entity
->guid,
80
]),
81
'item_class'
=> $has_subscriptions ?
''
:
'hidden'
,
82
'link_class'
=> $link_classes,
83
'data-toggle'
=>
'entity_subscribe'
,
84
]);
85
86
return
$result
;
87
}
88
}
elgg_is_logged_in
elgg_is_logged_in()
Returns whether or not the user is currently logged in.
Definition:
sessions.php:43
elgg_generate_action_url
elgg_generate_action_url(string $action, array $query=[], bool $add_csrf_tokens=true)
Generate an action URL.
Definition:
pagehandler.php:197
Elgg\Notifications\RegisterSubscriptionMenuItemsHandler\__invoke
__invoke(\Elgg\Event $event)
Add menu items to a menu.
Definition:
RegisterSubscriptionMenuItemsHandler.php:27
$result
$result
Definition:
set_maintenance_mode.php:11
elgg_echo
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition:
languages.php:17
ElggMenuItem\factory
static factory(array $options)
Create an ElggMenuItem from an associative array.
Definition:
ElggMenuItem.php:130
MenuItems
Elgg
Definition:
ActionsService.php:3
$entity
$entity
Definition:
reset.php:8
Elgg\Notifications
Definition:
CreateCommentEventHandler.php:3
ElggEntity
Definition:
ElggEntity.php:52
Elgg\Notifications\RegisterSubscriptionMenuItemsHandler
Register menu items to any menu to handle entity subscriptions.
Definition:
RegisterSubscriptionMenuItemsHandler.php:14
elgg_get_logged_in_user_entity
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition:
sessions.php:24
Elgg\Menu\MenuItems
A collection of menu items.
Definition:
MenuItems.php:10
Elgg\Event
Models an event passed to event handlers.
Definition:
Event.php:11
Generated on Sat Oct 12 2024 00:02:37 for Elgg by
1.8.11