Elgg
Version 6.3
engine
classes
Elgg
Notifications
CreateContentEventHandler.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Elgg\Notifications
;
4
11
class
CreateContentEventHandler
{
12
20
public
function
__invoke
(\
Elgg
\
Event
$event): void {
21
$entity
= $event->getObject();
22
if
(!
$entity
instanceof \
ElggObject
&& !
$entity
instanceof \
ElggGroup
) {
23
return
;
24
}
25
26
$owner
=
$entity
->getOwnerEntity();
27
if
(!
$owner
instanceof \
ElggUser
) {
28
return
;
29
}
30
31
// If an object is subscribable we should subscribe the owner
32
if
(
$entity
instanceof \
ElggObject
&& !
$entity
->hasCapability(
'subscribable'
)) {
33
// not subscribable, so check if there are notification events for this object
34
$notification_events
=
_elgg_services
()->notifications->getEvents();
35
if
(!isset(
$notification_events
[
$entity
->getType()]) || !isset(
$notification_events
[
$entity
->getType()][
$entity
->getSubtype()])) {
36
// no notification events registered for this entity type/subtype
37
// so there is no need to subscribe
38
// this also prevents the database from flooding with relationships that are never used (e.g. subscriptions to site notifications)
39
return
;
40
}
41
}
42
43
$enabled_methods =
$owner
->getNotificationSettings(
'content_create'
,
true
);
44
if
(empty($enabled_methods)) {
45
return
;
46
}
47
48
$entity
->addSubscription(
$owner
->guid, $enabled_methods);
49
}
50
}
$entity
$entity
Definition:
reset.php:8
$owner
$owner
Definition:
upload.php:7
ElggGroup
Definition:
ElggGroup.php:14
ElggObject
Definition:
ElggObject.php:15
ElggUser
Definition:
ElggUser.php:28
Elgg\Event
Models an event passed to event handlers.
Definition:
Event.php:11
Elgg\Notifications\CreateContentEventHandler
Apply subscriptions based on preferences.
Definition:
CreateContentEventHandler.php:11
Elgg\Notifications\CreateContentEventHandler\__invoke
__invoke(\Elgg\Event $event)
Subscribe to content you just created in order to receive notifications.
Definition:
CreateContentEventHandler.php:20
_elgg_services
_elgg_services()
Get the global service provider.
Definition:
elgglib.php:337
Elgg\Notifications
Definition:
CreateCommentEventHandler.php:3
Elgg
Definition:
ActionsService.php:3
$notification_events
foreach($entity->getSubscriptions($user->guid) as $subscription) $notification_events
Definition:
details.php:44
Generated on Sun Sep 7 2025 00:00:22 for Elgg by
1.9.1